def complex():
answer = raw_input("Would you like to run this program?")
answer = answer.lower()
money = 5
if "yes" in answer:
print money
money = money - 1
complex()
else:
quit()
complex()
For some reason, every-time I enter “yes” into the raw_input it spits out 5. But I want it to spit out 5 then when I type yes again I want it to spit out 4, and then if I type yes again I want it to spit out 3….
I fixed this by using the Global statement:
money = 5
def complex():
answer = raw_input("Would you like to run this program?")
answer = answer.lower()
if "yes" in answer:
global money
print money
money = money - 1
complex()
else:
quit()
complex()
This is what your procedure is doing :
moneyto 5moneywhich is 5.moneyto 5 – 1 = 4complex()moneyto 5moneywhich is 5.moneyto 5 – 1 = 4complex()…
etc.
As you can see your procedure is overwriting the desired value (4) with the value of 5 with each iteration that that is why it is not working as you desire.
What you could do is make a loop to run x number of times after
moneyhas been set to five.