+ 5

No numeral

Hi, i cannot solve this problem in code coach My first try is: a=str(input()) a=a.replace("0", "zero") a=a.replace("1", "one") a=a.replace("2", "two") a=a.replace("3", "three") a=a.replace("4", "four") a=a.replace("5", "five") a=a.replace("6", "six") a=a.replace("7", "seven") a=a.replace("8", "eight") a=a.replace("9", "nine") a=a.replace("10", "ten") print(a) But the hidden test case 3 is false, so i thought the problem is numer bigger than 10 (f.e: 12 will become onetwo) So here is my second try: https://code.sololearn.com/c1DVm102H33m/?ref=app It take care of all number from 0-10 and will print 12 as 12, but the hidden test case 3 is still false 😭 Can someone please help me or explain the problem with my code?

8th Aug 2021, 9:13 AM
Hieu Le Chi
Hieu Le Chi - avatar
7 Respostas
+ 7
Hieu Le Chi , have a look at the code for a special test case: https://code.sololearn.com/cA76jNJY7s2T/?ref=app
8th Aug 2021, 11:09 AM
Lothar
Lothar - avatar
+ 11
Hieu Le Chi , even if you correct your code according to some recommendations here, the result will fail. the reason is, that you use the input string for iteration and processing. this will lead to a result of '.. oneone ...' if the string contains the number 11 and do on... you should try to follow this: ▪︎the input string has to be split to individual words (this will create automatically a list) ▪︎use this list and iterate through it by using a for loop - if word in the loop variable does contain a number (using isdigit()), replace the element in the list (number) with the 'word number'. to do so, you need an index number to access the respective element - in each other case do nothing ▪︎after iteration through list is finished, the list should contain the correct words ▪︎for doing the output of the list, use print(" ".join(... your_list_name))
8th Aug 2021, 9:47 AM
Lothar
Lothar - avatar
+ 7
If input is 10 cats output should be ten cats not one zero cats. You can start with 10 to correct it. a=str(input()) a=a.replace("10", "ten") ...
8th Aug 2021, 9:21 AM
Simba
Simba - avatar
+ 6
Thank you guys so much, I have finally solved the problems. What a great community we have here 😊 P.S: here is my finished code https://code.sololearn.com/c2t3O09Dstz0/?ref=app
8th Aug 2021, 10:06 AM
Hieu Le Chi
Hieu Le Chi - avatar
+ 5
Your code doesn't works for input like "1,0" and also it is " 10 ":" ten ". (watch the Space before ten)
8th Aug 2021, 9:31 AM
Abhay
Abhay - avatar
+ 2
[EDITED] Hieu Le Chi Here are two solutions: print(*map(lambda x: ("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten")[int(x)] if x.isdigit() and 0 <= int(x) < 11 else x, input().split())) # Hope this helps
8th Aug 2021, 5:12 PM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Lothar, Thank you much for improving my code 🙏🤝, you are amazing 😊
8th Aug 2021, 11:22 AM
Hieu Le Chi
Hieu Le Chi - avatar