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()
出于某种原因,每次我在 raw_input 中输入“yes”时,它都会吐出 5。但是我希望它吐出 5,然后当我再次键入 yes 时,我希望它吐出 4,然后如果我再次键入 yes,我想让它吐出 3....
我通过使用 Global 语句解决了这个问题:
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()