2015-11-08 33 views
0
def beg(): 
    if race == "orc": 
     print ("You come to the border of the valley but the path splits into two seperate paths one going east and the other going west, there is no indication of which one goes where but you figure you will go one way.") 
     print("Your options are: ") 
     print("1. left") 
     print("2. right") 
     time.sleep(10) 
     direction1 = input("You decicde to go: ") 
     if direction1 == "left": 
      print ("You decide to go left towards the snowy forest in which the snow elves live") 
     if direction1 == "right": 
      print ("You decide to go right towards the desert which is famous of the amount of bandits that are found there.") 
     else: 
      print ("Please pick one of the listed options") 
      beg() 

基本上我得到的問題是,當代碼運行並選擇合適的工作原理,並打印文本,但是當你選擇離開它只是不斷循環BEG()錯誤:一直循環

+0

對於縮進是語言的一部分的語言(如Python),您應該始終對您發佈的代碼進行校對,以便縮進是正確的。 –

回答

1

你忘了使用elif作爲「正確」的情況下,因此,而不是一個單一的鏈接if如您所願,您有兩個獨立的if聲明,其中第二個聲明else。只是改變了「正確」的考驗:

elif direction1 == "right": 

這樣,你會跳過else,如果它的「左」。

+0

感謝您的幫助 –