就是quit是while终止循环的条件,但是如果输入的是数字可以进行if语句,但是输入quit就不能进行if语句然后判错,请问有没有比较巧妙的解决方法(不改变大体的语句下)?
谢谢大佬们了
quit并不是终止while的条件,而是判断要不要进入while,因此,就需要先判断输入的到底是字符还是数字
prompt = "How old are you?"
prompt += "\nEnter 'quit' to end the program."
message = input(prompt)
if message.isalpha():#判断输入的是否为字符
if message == 'quit':
exit
else:
while True:
if int(message) < 3 and int(message) > 0:
print('You are free.')
elif int(message) >= 3 and int(message) <= 12:
print('The price is 10 dollars.')
elif int(message) > 12:
print('The price is 15 dollars.')
break
while True:
message = input(prompt)
if str == 'quit': break
if int(message)< 3 and ...