下面的代码片段。我试着搞乱another answer posted on here,但似乎一点也不管用。我不知道我做错了什么。在Xubuntu 18.04 LTS上使用Python3。代码如下:while True:
try:
print("Your room is DARK, yet a light flashes red. What do you do?")
print("")
print("1. Look around.")
print("2. There's a lamp somewhere...")
print("3. Go back to bed.")
print("")
ans = int(input(">>> "))
if ans == 1:
print("")
print("Too dark to see... better find a light...")
time.sleep(2)
if ans == 2:
print("")
print("Fumbling, you turn on your nightstand lamp...")
break
if ans == 3:
print("")
print("You sleep away the troubles... but you can't stay asleep...")
time.sleep(1)
print("")
print("Back to the world of the living...")
if ans == str('q'):
sys.exit(0)
except ValueError:
print("")
所以,当用户输入“q”时,我希望程序关闭。我好像一点也做不到。在