0

what's wrong?!

https://www.sololearn.com/coach/64?ref=app x = input() z = "" #1/6 test cases failed for i in x: if i.isdigit(): if i == "1": x = x.replace(i, "one") elif i == "2": x = x.replace(i, "two") elif i == "3": x = x.replace(i, "three") elif i == "4": x = x.replace(i, "four") elif i == "5": x = x.replace(i, "five") elif i == "6": x = x.replace(i, "six") elif i == "7": x = x.replace(i, "seven") elif i == "8": x = x.replace(i, "eight") elif i == "9": x = x.replace(i, "nine") elif i == "10": x = x.replace(i, "ten") elif i == "0": x = x.replace(i, "zero") print(x)

14th Mar 2020, 12:41 AM
Ahmed Mohamed
4 Antworten
+ 4
By replacing ones first before the tens, you have essentially turned tens into ones and zeroes.
14th Mar 2020, 1:40 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
Move i == "10" to the top of if statement. So that "10" will be checked from the string and replaced.
14th Mar 2020, 1:30 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
same
14th Mar 2020, 1:37 AM
Ahmed Mohamed
0
worked, thanks for i in x: if i.isdigit(): if i == "1": n = x[x.index(i)+1] if n.isdigit(): if n == "0": x = x.replace(i, "ten") x = x.replace(n, "") else: x = x.replace(i, "one") ...
14th Mar 2020, 2:00 AM
Ahmed Mohamed