我的代碼:除非你進入初學者的Python - 到目前爲止有一個字符串或一個變量在一個循環接聽
prompt = "\nEnter 'quit' when you are finished."
prompt += "\nPlease enter your age: "
while True:
age = input(prompt)
age = int(age)
if age == 'quit':
break
elif age <= 3:
print("Your ticket is free")
elif age <= 10:
print("Your ticket is $10")
else:
print("Your ticket is $15")
程序運行正常「退出」來結束循環。我明白age = int(age)
將用戶輸入定義爲一個整數。我的問題是,如何將其更改爲不將「quit」視爲整數,並在輸入「quit」時結束循環。