+ 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)
12 Answers
+ 5
Have you tried your code with a few test inputs?
What result did you get?
+ 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.
+ 3
venkatesh sontyana , no start replacing with the case for 10 and then all other.
+ 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.
+ 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
+ 1
Ine test case is failed. Remaining 5 are satisfied
+ 1
I tried all single digit numerals i got correct output
+ 1
No no,still i am getting single output
+ 1
Will u please try it for me
+ 1
I am trying hard but, i am not getting whats wrong in it
+ 1
I too got the same idea just now. I am trying in that direction.
Thank you
+ 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.