初学PYTHON,WHILE=FALSE后,不退出程序。
prompt = "\nHow old are you ? "
prompt += "\nYou can input 'quit' to quit !\n"
active = True
while active :
age = input(prompt)
if age == 'quit':
acitve = False
else:
age = int(age)
if age < 3:
print("Free!")
elif age <= 12:
print("The ticket price is 10 dollars!")
else:
print("The ticket price is 15 dollars!")
在CMD下运行的,SUBLIME无法运行INPUT,运行不出错,只是QUIT不退出程序。
网上找了一样的,比对了好像没问题,初学者没找出问题所在。
(prompt = "\nPlease enter the your age:"
prompt += "\n(Enter 'quit' when you are finished.) "
active=True
while active :
age = input(prompt)
if age == 'quit':
active=False
else:
age=int(age)
if age<3:
print("free")
elif (age>=3 and age<=12):
print("The ticket price is 10 dollars.")
else:
print("The ticket price is 15 dollars."))