What is the error in my code??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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)

16th Aug 2020, 8:58 AM
Jayendra Todawat
Jayendra Todawat - avatar
6 Answers
+ 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)
16th Aug 2020, 9:17 AM
Rohit
+ 4
~ swim ~ RKK Thnx for suggestions.
16th Aug 2020, 9:26 AM
Jayendra Todawat
Jayendra Todawat - avatar
+ 2
~ swim ~ Then plz help me to deal with it.
16th Aug 2020, 9:05 AM
Jayendra Todawat
Jayendra Todawat - avatar
+ 2
RKK ~ swim ~ But test case 6 is failing. Whats the problem then???
16th Aug 2020, 9:31 AM
Jayendra Todawat
Jayendra Todawat - avatar
+ 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"
16th Aug 2020, 9:35 AM
Rohit
+ 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.
16th Aug 2020, 9:32 AM
Rohit