+ 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))

16th Sep 2020, 8:22 AM
Eleojo Emmanuel Adegbe
Eleojo Emmanuel Adegbe - avatar
4 Answers
+ 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)
16th Sep 2020, 8:28 AM
šŸ‘‘FabVabšŸ‘‘
šŸ‘‘FabVabšŸ‘‘ - avatar
+ 1
Thanks Fab but please can you tell me why mine didn't pass some test cases??
16th Sep 2020, 8:39 AM
Eleojo Emmanuel Adegbe
Eleojo Emmanuel Adegbe - avatar
+ 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.
16th Sep 2020, 9:26 AM
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ - avatar
+ 1
Thanks but even when I type "I have ten apples " ...it works just fine.. still yet to find the problem....,:-(:-(
16th Sep 2020, 12:51 PM
Eleojo Emmanuel Adegbe
Eleojo Emmanuel Adegbe - avatar