it fail in 3 test case | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

it fail in 3 test case

d1={"0":"zero","1":"one","2":"two","3":"three","4":"four","5":"five","6":"six","7":"seven","8":"eight","9":"nine","10":"ten"} n=input() for i in n: if i in d1: n=n.replace(i,d1[i]) print(n)

29th Dec 2019, 5:09 PM
Nihal Gupta
Nihal Gupta - avatar
9 Answers
+ 6
That's why I said you have to do 10 *before* the loop. dict will check for 1 first. '110' -> 'oneone0' No 10 left.
30th Dec 2019, 3:48 AM
HonFu
HonFu - avatar
29th Dec 2019, 8:17 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 8
Hi Nihal gupta Make sure to link code coach challenge link too while asking question. You need to read the code coach problem properly to correct your code(you need to account for 10 too) I hope it helps.
29th Dec 2019, 5:27 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 4
Nihal gupta , I think you should include in your dictionary also "10" 🐱
29th Dec 2019, 5:29 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 3
where is the problem in this code?
29th Dec 2019, 5:10 PM
Nihal Gupta
Nihal Gupta - avatar
+ 3
i already try with including 10 in my dict but it also not work
30th Dec 2019, 2:23 AM
Nihal Gupta
Nihal Gupta - avatar
+ 3
ok thank you
30th Dec 2019, 4:33 AM
Nihal Gupta
Nihal Gupta - avatar
+ 2
You first have to replace '10', and then the loop.
29th Dec 2019, 7:29 PM
HonFu
HonFu - avatar
+ 1
I think its better to use a list and replace all numbers because in your code 10 is considered as two character. So you need to loop the string as "word" wise.
10th Jan 2020, 7:18 AM
Shobhith J B
Shobhith J B - avatar