+ 2

No Numerals challenge🙋

Help me out please in no numerals challenge IDk why but it is falling the 3rd (hidden) test and passes all others😕 Here's my code dict={'0':'zero', '1':'one', '2':'two', '3':'three', '4':'four', '5':'five', '6':'six', "7":"seven", "8":"eight", "9":"nine", "10":"ten"} text=input() for key,value in dict.items(): text = text.replace(key,value) print(text)

9th Aug 2021, 2:30 PM
Rambo
13 ответов
+ 10
Rambo , if you input like : 1 2 3 11 123 the output will be: one two three oneone onetwothree the reason is, that you are looking at characters, but it would be better to look for words ▪︎split the input text by space. this gives a list of words. ▪︎then iterate through this list by using a for loop, that gives you one word after the other . you also need a variable for an index number - check if current word is in the dict. - if yes -use dictionary to replace the current element in the list with the help of the index ▪︎finally use join() to put the list to a string and output the string this should help to solve the exercise
9th Aug 2021, 4:31 PM
Lothar
Lothar - avatar
+ 7
Start with ten dict={"10":"ten", '0':'zero'...
9th Aug 2021, 2:52 PM
Simba
Simba - avatar
+ 4
Simba Thank you but why what's wrong with the third test , and what happens when we place "10" first in the dictionary And Isn't there any other way..
9th Aug 2021, 3:09 PM
Rambo
+ 4
If input is 10 your code gives onezero instead of ten. Because, it checks keys and values respectively.
9th Aug 2021, 3:44 PM
Simba
Simba - avatar
+ 3
Simba Ohh 😅 Tysm But isn't there another way because what if it need to contain other 2digit numbers
9th Aug 2021, 3:47 PM
Rambo
+ 2
Rambo How about this one? :- for x in input().split(): print(dict.get(x, x), end=" ") # Hope this helps
10th Aug 2021, 6:22 AM
Calvin Thomas
Calvin Thomas - avatar
+ 2
Jan Novák It's waste of time trying to implement negative numbers!
11th Aug 2021, 10:17 AM
Jan
Jan - avatar
+ 1
Simba bro??
9th Aug 2021, 4:09 PM
Rambo
+ 1
Ermias Bibi Off-topic comments in the Q&A section will be discouraged. Please post this in your feed instead. I hope it helps.
11th Aug 2021, 2:22 PM
Calvin Thomas
Calvin Thomas - avatar
0
Rambo, are you already done with the third test? If not, my quess is that there is a negative number, I will try to implement negative numbers...
10th Aug 2021, 1:30 PM
Jan Novák
Jan Novák - avatar
- 1
Guys what is going on here
11th Aug 2021, 2:30 PM
Marlina Woo
- 2
Cool
11th Aug 2021, 2:29 PM
Ermias Kebede
Ermias Kebede - avatar
- 3
Anyone interested in showing me the clear differences between phyton , JavaScript and php , I hope you will illustrate your explanation with examples ? One last thing about their critical syntax differences should be included .
11th Aug 2021, 2:05 PM
Ermias Kebede
Ermias Kebede - avatar