Converting numerls 10 and under to its English names fails in one of the hidden test case. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Converting numerls 10 and under to its English names fails in one of the hidden test case.

I wrote a code which basically takes a string of input and if the input contain numbers 10 and below it will simply convert those to english name. Like 2 converted to two likewise. But every time I run it i get one error which is hidden. What is wrong with the code? x = input().split() dict = {'ten': '10','9':'nine','8':'eight','7':'seven','6':'six','5':'five','4':'four','3':'three','2':'two','1':'one','0':'zero'} y = [] for i in x: if i not in dict: y.append(i) else: y.append(dict[i]) print(' '.join(y))

27th Aug 2021, 5:17 PM
Kaushal Sapelwar
Kaushal Sapelwar - avatar
3 Answers
+ 1
10:ten instead of ten:10
27th Aug 2021, 5:26 PM
Abhay
Abhay - avatar
+ 1
The first dictionary item should be '10': 'ten' instead of 'ten': '10'
27th Aug 2021, 5:26 PM
Simon Sauter
Simon Sauter - avatar
+ 1
Thanks that was overlooked 😅
27th Aug 2021, 5:30 PM
Kaushal Sapelwar
Kaushal Sapelwar - avatar