通貨値を含む文字列があります。
文字列から文字ごとに読み取る必要があり、関数はresult = 0
のすべての値に対して返さなければなりませんval
。
例: これらの値のいずれかを持つことができるstring = "You Score is MX var."
場所var
[14 , 14.98 , 114 , 114.98 , 1116 , 1,116 , 1116.78 , 1,116.18 , 11,12,123 , 1,12,123.89 ... and so on...]
マイコード
def evaluate():
result , count = 0 , 0
dot , comma = False , False
while (index_of_String < Len_of_string):
ch = string[index_of_String]
if (ch == '.'):
if (dot == True):
break ;
dot = True
elif (ch == ','):
if (dot == True):
break
comma = True
elif not (ch >= '0' and ch <= '9'):
if not (ch == ' ' or ch == ','):
result = -1
break
else:
if (dot == False):
count += 1
print ("Char %c" % ch)
index_of_String += 1
print ("count of numeric digits %d" % count)
if (result == 0):
if dot == False:
result = -1
if comma == False:
if (count > 3):
result = -1
return (result, index_of_String)
必要な出力
string = "You Score is MX 14."
result = 0
string = "You Score is MX 14.89."
result = 0
string = "You Score is MX 1114.89."
result = 0
string = "You Score is MX 1,114.89."
result = 0
string = "You Score is MX 11,,,14.89."
result = -1 (fail)
string = "You Score is MX 11.14.89."
result = -1 (fail)
string = "You Score is MX 1,114.89."
result = 0
string = "You Score is MX 1,14.89."
result = -1 (fail)
string = "You Score is MX 1,11,114.89."
result = 0
これらすべてのケースでコードを機能させるには、どのような変更が必要ですか。
変更のヘルプ??