+ 2
What is the error in my code???
msg1=input() ms1=msg1.split() dict1={'0':"zero",'1':"one",'3':"two",'3':"three",'4':"four",5:"five",'6':"six",'7':"seven",'8':"eight", '9':"nine"} msg2=[] for i in ms1: if i.isdigit(): msg2.append(dict1[i]) else: msg2.append(i) ms3=' '.join(msg2) print(ms3)
9 ответов
+ 5
msg1=input()
ms1=msg1.split()
dict1={'1':"one",'2':"two",'3':"three",'4':"four",'5':"five",'6':"six",'7':"seven",'8':"eight",
'9':"nine",'10':"ten"}
msg2=[]
for i in ms1:
if i.isdigit():
msg2.append(dict1[i])
else:
msg2.append(i)
ms3=' '.join(msg2)
print(ms3)
# (Jayndra Todawat no changes in code, only added "10":"ten" to dict1 and little modification with dict1 and its working like charm)
+ 2
~ swim ~ Then plz help me to deal with it.
+ 2
Jayndra Todawat
dict1={'0':"zero",'1':"one",'3':"two",'3':"three",'4':"four",5:"five",'6':"six",'7':"seven",'8':"eight"...
check your key value nicely..
you have '3':'two' and also 5 is missing single quotes and also add '10':"ten"
+ 1
~ swim ~ you're right, the code would break/fail for input like "abcd10efg" and I agree with you too that char scanning would be a good solution.