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)

2nd May 2023, 11:16 AM
Tim M
4 Antworten
+ 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( ... )
2nd May 2023, 11:27 AM
Ipang
+ 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)
2nd May 2023, 12:12 PM
Tim M
+ 1
Alright! good job!
2nd May 2023, 12:56 PM
Ipang
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)
3rd May 2023, 3:38 PM
Amirreza Abdi
Amirreza Abdi - avatar