+ 1
No numerals, code coach
I have been trying to solve the no numerals code coach problem using python. This is the code i cameup with but it doesn't work. I cant figure out why. Will someone help? I dont need the solution for the problem. I just need an explanation as to why it wont work. Im a beginner with python btw s=input() nums=["zero","one","two","three","four","five","six","seven","eight","nine","ten"] for i in range(11): s.replace(str(i),nums[i]) print(s)
7 Answers
+ 5
You need to restore your new string in s.
s = s.replace(str(i),nums[i])
There is one more problem after that:
Try to run your code with 10 and see what happens. đ
+ 5
A String is immutable.
So replace() returns another String and s keeps the same.
Assign the return of replace to s.
+ 5
I'm hunting it right now. Thank you guys for that valuable information! and thanks for helping out a beginner.
+ 4
Salman Nazeer u did a good job đđ
+ 2
Found the bug. Onezero. Thanks for pointing me in the right direction HonFu and Oma. I appreciate you guys giving me an oppurtunity to learn from my mistakes.
+ 2
I just added s=s.replace('onezero','ten')
when the program exited the loop. I know its not a great fix but i just fit it in