0
All of input give right output. But input three make me sick. //Fixed
6 odpowiedzi
+ 4
https://code.sololearn.com/cFu840UEC1Ez/#py
https://www.sololearn.com/Codes?ordering=MostRecent&query=No%20Numerals
Keep learning & happy coding :D
+ 6
Yohann Stantine ,
(1) what we have to do is to split the input sentence at the word boundaries => spaces. this can be done direct with the input() function. this results
in a list.
(2) the next step is to loop over the list. we take the value from the loop variable and we try to find if it is a key in the dictionary.
to do this we use the dictionary method get(). get can have 2 arguments: get(<key to search for>, <default value>)
in case the content of the loop variable is found, the value from dictionary will be returned, if it can not be found, the loop variable will be returned.
given = input().split()
numeral = {'0':'zero', '1':'one', '2':'two', '3':'three', '4':'four', '5':'five',
'6':'six', '7':'seven', '8':'eight', '9':'nine', '10':'ten',}
lst =[]
for i in given:
lst.append(numeral.get(i, i))
print(' '.join(lst))
this is your code cleaned up:
https://code.sololearn.com/cbac4ZMeJusj/?ref=app
+ 5
SoloProg ,
your code seems to struggle with an input like this: '1 2 100 hello'
+ 3
Three is ok, but ten is a problem. Because you are looping over each single char in 'given'. That can be '1' or '0', but never '10'. So you will always get one zero instead of ten.
+ 3
Lothar ,
try the code now it should work let me know if something goes wrong.
I already completed the challenge.
0
Go see a doctor so