Can anyone help in no numerical in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone help in no numerical in python

x=input() d= {"1":"one", "2":"two", "3":"three","4":"four","5":"five","6":"six","7":"seven","8":"eight","9":"nine","10":"ten","0":"zero"} for i in d: x=x.replace(i,d[i]) print(x) ...this is my code but failing one test case....can anyone tell what is wrong in this code

22nd Sep 2020, 5:43 PM
sumit mehta
sumit mehta - avatar
3 Answers
+ 8
To avoid the trouble by detecting single digit numbers or two-digit numbers in this task, the input could be split. So 10 is really "ten" and not "onezero".
22nd Sep 2020, 7:26 PM
Lothar
Lothar - avatar
+ 6
I think what Jayakrishna🇮🇳 said is correct. In your for loop, 'i' is assigned only a single character each time, so it will never find "10". It will find "1" and change to "one" and then find the "0" and change it to "zero", so "10" -> "onezero".
22nd Sep 2020, 6:59 PM
Russ
Russ - avatar
+ 1
Similar to key : value for 0,you shloud take 1 also after 10 in dictionary i guess..
22nd Sep 2020, 6:54 PM
Jayakrishna 🇮🇳