0
Why is this code not working for the No Numerals challenge? In Python
nums = ("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten") msg = input().lower() for i in range(10, -1, -1): msg.replace(str(i), nums[i]) print(msg)
4 Respuestas
+ 9
String is immutable, so the new string from replace() method (which contains updated version) needs to be reassigned back to <msg> itself
for i in range( 10, -1, -1 ):
msg = msg.replace( ... )
+ 3
Thanks, I knew I was missing something obvious! And even then test cases 4 and 5 were still failing. Thankfully removing .lower() fixed that(so much for the input being lowercase!). :)
Final code:
nums = ("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten")
msg = input()
for i in range(10, -1, -1):
msg = msg.replace(str(i), nums[i])
print(msg)
+ 1
Alright! good job!
0
In the 4th line (for i in range...) you need to write the small number first
For example in this case you have to do this :
for i in range (-1,10)