如何允许用户退出程序

时间:2016-11-15 00:22:49

标签: python exit

我正在制作文字冒险游戏,我试图让用户使用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

这些行在代码中都正确缩进(网站在复制粘贴时会很奇怪)。任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:0)

你的程序几乎没问题,事实上它在python3中运行得很好。问题是在python2中,input实际上评估您的输入。为了支持python2,请使用raw_input

答案 1 :(得分:-2)

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:

            break

现在,当您输入“Q”或“q”时,程序将退出。 这是关于制表的。那是你问的吗?