2014-07-23 43 views
0

在你最初的問題是你拿了多少,它工作正常。如果你輸入0就會死亡,500萬美元表示很好。它說好的後,它退出程序並忘記其餘的代碼。我該如何移動到這個遊戲/故事中的代碼的不同部分

如何獲取python加載代碼的下一部分並運行它。

from sys import exit 

def bank_vault(): 
    print "This room is full of money up to 5 million dollars. How much do you take?" 

    choice = raw_input("> ") 
    if "0" in choice: 
     dead("You are robbing a bank and took nothing... The cops shot you in the face.") 
     how_much = int(choice) 

    if how_much < 5000000: 
     print "Nice take, now you have to escape!" 
     escape_route() 

def escape_route(): 
    print "There are cops blocking the front door." 
    print "There are cops blocking the back door." 
    print "There is no way to get out of there." 
    print "You see a small opening on the ceiling." 
    print "Type ceiling to go through it." 
    print "Or type stay to try your luck." 
    escaped_cops = False 

    while True: 
     choice = raw_input("> ") 

     if choice == "stay": 
      dead("Your bank robbing friends left your stupid ass and the cops shot you in the face. Idiot move dipshit.") 

     elif choice == "ceiling" and not escaped_cops: 
      print "You escaped! Now wash that money and don't go to prison." 
      escaped_cops = True 

def dead(why): 
    print why, "" 
    exit(0) 

bank_vault() 
+0

需要重新格式化......而且,你似乎是想你'choice'轉換成'int'你打過電話後'死「的功能,所以這是行不通的。 – elParaguayo

回答

0

酷遊戲。我喜歡遊戲,並希望嘗試改進您的代碼。下面的代碼工作在Python 3下應該對Python的2工作:

from sys import exit 

try: input = raw_input   # To make it work both in Python 2 and 3 
except NameError: pass 

def bank_vault(): 
    print("This room is full of money up to 5 million dollars. How much do you take?") 

    how_much = int(input("> ")) # Why not eliminate choice variable here? 

    if how_much == 0: 
     dead("You are robbing a bank and took nothing... The cops shot you in the face.") 
    elif how_much < 5000000: # Changed to else condition 
     print("Nice take, now you have to escape!") 
    else:      # Added a check 
     dead("There isn't that much!") 


def escape_route(): 
    print("There are cops blocking the front door.") 
    print("There are cops blocking the back door.") 
    print("There is no way to get out of there.") 
    print("You see a small opening on the ceiling.") 
    print("Type ceiling to go through it.") 
    print("Or type stay to try your luck.") 
    escaped_cops = False 

    while not escaped_cops: 
     choice = input("> ") 

     if choice == "stay": 
      dead("Your bank robbing friends left your stupid ass and the cops shot you in the face. Idiot move dipshit.") 
     elif choice == "ceiling": 
      print("You escaped! Now wash that money and don't go to prison.") 
      escaped_cops = True 

def dead(why): 
    print(why) 
    exit(0) 

bank_vault() 
escape_route() 
+0

非常感謝! – PythonTrubble

+0

沒問題。如果它適合你,請接受答案。 – arocks

0

您必須調用函數escape_route而不是退出。

此外,在檢查選擇時,無論如何,請致電dead

在回答您的評論:

你需要檢查它是否是0,則調用dead,如果它不是0不與別人打擾,直接去if how_much < 5000000並調用escape_route

你如果它不是0,則需要嘗試將輸入轉換爲int

如果他們需要超過5密耳會發生什麼?

+0

是的,我只是想說,我該怎麼做?我知道這是一個愚蠢的問題,但我是一個Python的noob。 – PythonTrubble

+0

更新我的答案=) –

+0

我拿出了其他東西,但同樣的事情不斷髮生。 – PythonTrubble

相關問題