如何允许用户退出程序

2024-05-14 13:56:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个文本冒险游戏,我试图让用户退出游戏使用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

所有的行都在代码中正确地缩进(网站在复制粘贴时使其变得奇怪)。感谢任何帮助。在


Tags: andtheto代码youyourhaveprint
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”程序将退出。 是关于制表的。这就是你要的吗?在

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

相关问题 更多 >

    热门问题