+ 1
No numericals code coach challenge
Code written in python. Solved using dictionary and loop. When I am running this, it is passing 4/5 test cases. Can you help me find the bug in my code? https://code.sololearn.com/c775LgP2G2Hp/?ref=app
9 Answers
+ 2
Shaurya Agarwal your dictionary should be:-
word_num= {10:"ten", 1:"one" , 2:"two" , 3:"three" , 4: "four" , 5:"five" , 6:"six" , 7:"seven" , 8:"eight" , 9:"nine" , 0:"zero"}
+ 2
Write writing 10:"ten" before 1:"one". Because for ten it shows onezero
+ 2
Shaurya Agarwal ok so let us consider the input as 10. In your original code, the for loop first checks for the presence of the key "1" which is present in the input and hence it returns onezero instead of ten
Whereas when you write ten before one, it will first check for "10" and when it comes out to be True, the output will be ten
+ 1
I hope I was able to explain well. If not, then I recommend you to run your code in pythontutor. It's helpful
+ 1
shreya
That was really helpful, you explained quite well,
Thanks
+ 1
You can use two dictionaries,
in second use {'onezero':'ten'}
0
shreya it's working!
but can you pls elaborate I could not understand
0
shreya
Well that I understood but why is it so that I could not understand
0
Shadoff nice alternative