+ 1

No Numerals Code Coach

Can somebody tell why the #TestCase3 does not run when I write the following code in Python: text=str(input()) print(text.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').replace('0', 'zero').replace('10', 'ten'))

21st Oct 2024, 3:02 PM
Ishan Kumar Gupta
Ishan Kumar Gupta - avatar
2 Respuestas
+ 3
Ishan Kumar Gupta , if the input is: 1 2 3 8 9 0 10 100 the output will be: one two three eight nine zero onezero onezerozero ^^^^^^^^^ ^^^^^^^^^^^^^ maybe you should check the logig of the code. the task description says: Take a phrase and replace any instances of an integer from 0-10 and replace it with the English word that corresponds to that integer. so 10 should be `10` but not `onezero`, and 100 should not be replaced.
21st Oct 2024, 3:25 PM
Lothar
Lothar - avatar
+ 3
Try splitting the input string into a list of words. Then swap out the words in the list one at a time in a loop. Finally, convert the list back into a string to output it. It is a few additional lines of code, but far more reliable than the current method which cannot handle numbers with multiple digits such as 11, 100, 55.
21st Oct 2024, 5:18 PM
Jerry Hobby
Jerry Hobby - avatar