Why the following code is not satisfying all test cases of no numerals problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why the following code is not satisfying all test cases of no numerals problem

s=input("") x="" if "10" in s: x=s.replace("10","ten") print(x) else: for char in s: x=s.replace("0","zero").replace ("1","one").replace("2","two").replace("3","three").replace("4","four").replace("5","five").replace("6","six").replace("7","seven").replace("8","eight").replace("9","nine") print(x)

2nd Aug 2020, 11:49 AM
venkatesh sontyana
venkatesh sontyana - avatar
12 Answers
+ 5
Have you tried your code with a few test inputs? What result did you get?
2nd Aug 2020, 11:51 AM
HonFu
HonFu - avatar
+ 3
venkatesh sontyana , in my opinion you shouldn't print the text after replacing 10 in the if clause, because text can contain many numbers and you'll get wrong output. You need just one result => one print statement after you done all.
2nd Aug 2020, 11:58 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 3
venkatesh sontyana , no start replacing with the case for 10 and then all other.
2nd Aug 2020, 12:01 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 3
venkatesh sontyana , that's not the purpose. If you want to learn something you need to put a lot of effort to get some knowledge.
2nd Aug 2020, 12:04 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 3
Input contains 0 to10. (randoms) venkatesh sontyana Your program either if part executed or else part get executed. But think again, it needs both to execute and print result last.. Edit: Since you using s.replace instead of char.replace,then no need for loop
2nd Aug 2020, 12:05 PM
Jayakrishna 🇮🇳
+ 1
Ine test case is failed. Remaining 5 are satisfied
2nd Aug 2020, 11:53 AM
venkatesh sontyana
venkatesh sontyana - avatar
+ 1
I tried all single digit numerals i got correct output
2nd Aug 2020, 11:54 AM
venkatesh sontyana
venkatesh sontyana - avatar
+ 1
No no,still i am getting single output
2nd Aug 2020, 12:01 PM
venkatesh sontyana
venkatesh sontyana - avatar
+ 1
Will u please try it for me
2nd Aug 2020, 12:02 PM
venkatesh sontyana
venkatesh sontyana - avatar
+ 1
I am trying hard but, i am not getting whats wrong in it
2nd Aug 2020, 12:06 PM
venkatesh sontyana
venkatesh sontyana - avatar
+ 1
I too got the same idea just now. I am trying in that direction. Thank you
2nd Aug 2020, 12:11 PM
venkatesh sontyana
venkatesh sontyana - avatar
+ 1
Additionally to all those mentioned problems, there is no need to execute a replace within a loop over all characters. replace replaces all occurrences within a string.
2nd Aug 2020, 12:55 PM
Sandra Meyer
Sandra Meyer - avatar