0

Tips on my code.

Hey everyone, I am stuck on a coach challege and was wondering if I could get some tips or advice on what I have so far. This almost works on all the inputs except one. I don't need the direct answer but would just appreciate any advice you might have because my code is pretty basic. The challenge is to replace any digit under 10 in a sentence with the correct word for the number. phrase = str(input()) numbers = {"0":"zero", "1":"one", "2":"two", "3":"three", "4":"four", "5":"five", "6":"six", "7":"seven", "8":"eight", "9":"nine", "10":"ten"} fixed="" for i in phrase.split(): if i.isdigit()==True: i=int(i) if i >=10: i =str(i) fixed += i +" " else: fixed += numbers[str(i)] + " " else: fixed += i + " " print(fixed)

14th Feb 2020, 8:44 PM
DAYLINER BAND
DAYLINER BAND - avatar
1 Odpowiedź
+ 4
Your code doesn't work work because it checks whether the number is greater than or equal to 10, meaning it doesn't change 10. The line I'm talking about would have to be changed to: if i > 10: #the rest of your code goes here
14th Feb 2020, 8:53 PM
Jianmin Chen
Jianmin Chen - avatar