+ 2

No Numerals, Code Coach [Solved]

No Numerals, Code Coach problem My solution: str = input() num = {'0': 'zero', '1': 'one', '2': 'two', '3': 'three', '4': 'four', '5': 'five', '6': 'six', '7': 'seven', '8': 'eight', '9': 'nine', '10': 'ten'} for i in str: if i in num: str = str.replace(i, num.get(i)) print(str) I can't understand where it went wrong, everything seems fine and this solution passed each and every Test Cases except for Test Case #3. If you have idea of what it could be in Test Case #3 for this code coach, then please let me know. What could be the solution for this code coach?

10th Mar 2024, 9:26 PM
Armash Ansari
5 odpowiedzi
+ 2
Lisa Rain, Thank you everyone for all your responses. text = input().split(' ') numberToWord = {'0': 'zero', '1': 'one', '2': 'two', '3': 'three', '4': 'four', '5': 'five', '6': 'six', '7': 'seven', '8': 'eight', '9': 'nine', '10': 'ten'} noNumerals = [] for i in text: if i in numberToWord: noNumerals.append(numberToWord.get(i)) else: noNumerals.append(i) print(' '.join(noNumerals)) I have made some little modifications in the same code and it works fine now. Changes: 1. Converted input string into list using split() method. 2. Created an empty list. 3. Added elements to the list, until we check all the elements of the input string. 4. Finally printed the list as a string using join() method.
11th Mar 2024, 6:50 AM
Armash Ansari
+ 4
suppose the input is "10". your code translates it to "onezero" instead of "ten". also, in general, it is not a good idea to modify a string while iterating it.
10th Mar 2024, 11:08 PM
Lisa
Lisa - avatar
+ 1
Armash Ansari , Process the words (separated by spaces), not the characters. Hint: Check out the string method called split. https://docs.python.org/3/library/stdtypes.html#str.split
11th Mar 2024, 4:36 AM
Rain
Rain - avatar
+ 1
Armash Ansari , Lookin' good. 👍 People sometimes put [Solved] in the title after. That lets the people who read titles to see what to help with know they don't need to open it, and it lets anyone with a similar question who searches the topic know they can find useful info inside.
11th Mar 2024, 9:42 AM
Rain
Rain - avatar
0
for reference Code Coach No Numerals (medium) https://www.sololearn.com/coach/64?ref=app
11th Mar 2024, 4:29 AM
Rain
Rain - avatar