2016-11-15 50 views
0

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

所有的行都在代码中正确缩进(当复制粘贴时,网站变得很奇怪)。任何帮助表示赞赏。

+1

我把你的代码编辑成一个代码块。将来,您可以突出显示代码部分,然后单击带花括号的按钮{}'以缩进代码 – James

+0

请参阅https://stackoverflow.com/questions/543309/programatically-stop-execution-of- python-script – AnilRedshift

+0

什么是'退出'?也许你是用'()'来表示'break'或'quit()'。但删除'如果完成== True:退出',它应该按照您的预期工作。 – furas

回答

-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'程序将退出。 这是关于制表。这是你问的吗?

+0

[quit](https://docs.python.org/2/library/constants.html#quit)是一种退出的内置方法 – Hamms

+0

据我所知,我们使用'break'来断开循环,女巫我在这里看不到。所以'退出'会做,它的作品。 –

+0

@leaf我明白了。所以当我们使用while /如果break是停止的正确方法。但退出也会在这里工作? –

0

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

相关问题