【发布时间】:2016-11-15 00:22:48
【问题描述】:
我正在制作一款文字冒险游戏,并试图让用户使用 q 退出游戏。我不知道该输入什么,这是我的代码。
print ("Welcome to Camel!")
print ("You have stolen a camel to make your way across the great Mobi deset.")
print ("The natives want their camel back and are chasing you down! Survive your desert trek and out run the natives.")
print ("Welcome to Camel!")
print ("You have stolen a camel to make your way across the great Mobi deset.")
print ("The natives want their camel back and are chasing you down! Survive your desert trek and out run the natives.")
done = False
while done == False:
print("Print the letter only.")
print("A. Drink from your canteen.")
print("B. Ahead moderate speed.")
print("C. Ahead full speed.")
print("D. Stop for the night.")
print("E. Status check.")
print("Q. Quit.")
first_question = input("What do you want to do? ")
if first_question.lower() == "q":
done = True
if done == True:
quit
代码中的所有行都正确缩进(网站在复制粘贴时会变得很奇怪)。任何帮助表示赞赏。
【问题讨论】:
-
我将您的代码编辑成代码块。以后你可以高亮这段代码,然后点击大括号
{}的按钮为你缩进 -
quit是什么?也许你的意思是break或quit()- 和()。但是删除if done==True:quit,它应该可以正常工作。 -
您可以使用
if done: break或if done: sys.exit()。