+ 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

22nd Mar 2022, 4:58 AM
Shaurya Agarwal
Shaurya Agarwal - avatar
9 Antworten
+ 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"}
22nd Mar 2022, 5:34 AM
shreya
shreya - avatar
+ 2
Write writing 10:"ten" before 1:"one". Because for ten it shows onezero
22nd Mar 2022, 5:07 AM
shreya
shreya - avatar
+ 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
22nd Mar 2022, 5:45 AM
shreya
shreya - avatar
+ 1
I hope I was able to explain well. If not, then I recommend you to run your code in pythontutor. It's helpful
22nd Mar 2022, 5:46 AM
shreya
shreya - avatar
+ 1
shreya That was really helpful, you explained quite well, Thanks
22nd Mar 2022, 5:48 AM
Shaurya Agarwal
Shaurya Agarwal - avatar
+ 1
You can use two dictionaries, in second use {'onezero':'ten'}
22nd Mar 2022, 7:37 AM
Shadoff
Shadoff - avatar
0
shreya it's working! but can you pls elaborate I could not understand
22nd Mar 2022, 5:31 AM
Shaurya Agarwal
Shaurya Agarwal - avatar
0
shreya Well that I understood but why is it so that I could not understand
22nd Mar 2022, 5:35 AM
Shaurya Agarwal
Shaurya Agarwal - avatar
0
Shadoff nice alternative
22nd Mar 2022, 8:23 AM
Shaurya Agarwal
Shaurya Agarwal - avatar