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)
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.
+ 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)
+ 1
I used string.repalce(new, old, count) function for solving this one. I guess also there are other solutions.
+ 1
Orjiene Kenechukwu Wisdom
Use this simply will solved your problems.
for key, value in dict.items():
sentence = sentence.replace(key, value)
0
I have done that. It is ten that is faulty. It outputted 'one zero'. Thanks. But do you know any solution to that?
0
Can you please send me the code for to study and learn?
0
DishaAhuja Thanks