错误:保持循环

时间:2015-11-08 13:50:57

标签: python loops

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()

1 个答案:

答案 0 :(得分:1)

您忘记将elif用于“正确”的情况,因此您没有按照预期使用单个链接if,而是有两个独立的if语句,第二个包含else。只需将“正确”测试更改为:

elif direction1 == "right":

这样,如果它是“离开”,你将跳过else