command= " "
while True:
command = int(input("how old are you? "))
if command <= 12:
print("you're ticket is free.")
elif command <= 15:
print("you're ticket is $20.")
elif command > 15:
print("you're ticket is $50.")
elif command == "exit":
break
当我写 exit
时,它给出了一个 ValueError
,
ValueError: invalid literal for int() with base 10:'exit'
答案 0 :(得分:0)
在尝试将命令转换为 int 之前,您应该检查命令是否退出:
while True:
command = input("how old are you? ")
if command == "exit":
break
command = int(command)
if command <= 12:
print("you're ticket is free.")
elif command <= 15:
print("you're ticket is $20.")
elif command > 15:
print("you're ticket is $50.")