0

What can I do? No Numeral code in python fail in test 3. This is the code

dict = {'0': 'zero', '1': 'one', '2': 'two', '3': 'three', '4': 'four', '5': 'five', '6': 'six', '7': 'seven', '8': 'eight', '9': 'nine', '10': 'ten'} sentence = input() new_str = ' ' for ch in sentence: if ch.isdigit()==True: change=dict[ch] new_str = new_str + change else: new_str = new_str + ch print(new_str)

17th Jan 2020, 5:59 AM
Orjiene Kenechukwu Wisdom
Orjiene Kenechukwu Wisdom - avatar
7 Antworten
+ 3
Input: I have 10 dollars and 5 cents. And you will see what is wrong. Also numbers like 11,12...42, 100 shouldn't be changed.
17th Jan 2020, 6:04 AM
Mihai Apostol
Mihai Apostol - avatar
+ 3
"""here is my code. I got success after some tries, i hope it will help you""" str = str(input()) str = str.replace(" 0 "," zero ") str = str.replace("1 "," one ") str = str.replace("2","two") str = str.replace("3","three") str = str.replace("4","four") str = str.replace("5","five") str = str.replace("6","six") str = str.replace("7","seven") str = str.replace("8","eight") str = str.replace("9","nine") str = str.replace("10","ten") print(str)
17th Jul 2021, 5:27 AM
Sowmiyashree S
Sowmiyashree S - avatar
+ 1
I used string.repalce(new, old, count) function for solving this one. I guess also there are other solutions.
17th Jan 2020, 6:15 AM
Mihai Apostol
Mihai Apostol - avatar
+ 1
Orjiene Kenechukwu Wisdom Use this simply will solved your problems. for key, value in dict.items(): sentence = sentence.replace(key, value)
17th Jan 2020, 6:27 AM
DishaAhuja
DishaAhuja - avatar
0
I have done that. It is ten that is faulty. It outputted 'one zero'. Thanks. But do you know any solution to that?
17th Jan 2020, 6:09 AM
Orjiene Kenechukwu Wisdom
Orjiene Kenechukwu Wisdom - avatar
0
Can you please send me the code for to study and learn?
17th Jan 2020, 6:22 AM
Orjiene Kenechukwu Wisdom
Orjiene Kenechukwu Wisdom - avatar
0
DishaAhuja Thanks
17th Jan 2020, 6:40 AM
Orjiene Kenechukwu Wisdom
Orjiene Kenechukwu Wisdom - avatar