I am trying to write a piece of code that takes a string as input and replaces * for a range of numbers, sort of like:
I am * years old
0-10
I am 0 years old
I am 1 years old
...
This is an attempt to make my life easier on R while I also learn some Python. Here is my code:
yourtext = input(" ")
number = input(" ")
number = int(number)
while number > 0:
i = str(number)
print(i)
yourtext = yourtext.replace("*", i)
print(yourtext)
print(number)
number = number - 1
And right now, this returns:
*
5 (my inputs)
5
5
5
4
5
4
3
5
3
2
5
2
1
5
1
So it seems like the i inside the replace function is fixed at its value on the first iteration of the loop. Why is this and how can I change it? Thanks a lot for your help.