+ 2
Case 4 and 5 failed for the No numerals Code coach challenge. Please what is wrong with my code.?
prompt= input('').lower() list= prompt.split(' ') string = " " dic = { '1':'one' , '2':'two', '3':'three', '4':'four','5':'five', '6':'six' , '7':'seven', '8':'eight', '9':'nine', '10':'ten'} for word in list: for key in dic: if word == key: index= list.index(word) list[index]= dic[key] print(string.join(list))
4 Réponses
+ 5
Try this one 🤗
👇
numbers = {
'0': 'zero', '1': 'one', '2': 'two',
'3': 'three', '4': 'four', '5': 'five',
'6': 'six', '7': 'seven', '8': 'eight',
'9': 'nine', '10': 'ten',
}
phrases = input() # i need 2 pumpkins and 3 apples
result = ''
for i in phrases.split():
result += (numbers.get(i, i) + ' ')
print(result)
+ 1
Thanks Fab but please can you tell me why mine didn't pass some test cases??
+ 1
Eleojo Emmanuel Adegbe your code checks "1" first, making 10 can't never be checked.
For example input "I have 10 apples".
It found "1" in "10". And also found "1" in dic. The condition is true and make it become "I have one0 apples"
You can put 10 before 1 in dic to solve this.
+ 1
Thanks but even when I type "I have ten apples " ...it works just fine.. still yet to find the problem....,:-(:-(