以艰难的方式学习python - 练习36个功能问题

时间:2013-07-16 23:27:14

标签: python

我正在学习通过学习python的方式编写代码,我最近第一次陷入困境。对于这个练习,我们应该编写自己的游戏。我这样做了,但出于某种原因,每当我运行它时,right_room()函数在我输入答案后退出,而不是进入下一个房间。任何帮助将不胜感激。这是我的代码:

from sys import exit

def bear_room():
    print "You are in a room with a bear."
    print "You have two choices. left or right?"
    next = raw_input("> ")

    if next == "left":
        left_room()
    elif next == "right":
        right_room()
    else:
        print "No idea what that means..."

def left_room():
    print "You went left."
    print "There are two doors. right or straight"
    next = raw_input("> ")

    if next == "right":
        bear_room()
    elif next == "straight":
        second_left()
    else:
        print "What are you saying, bro?"

def second_left():
    print "You went straight."
    print "You again have two choices. straight or right?"
    next = raw_input("> ")

    if next == "straight":
        print "You won! Congrats."
        exit(0)
    elif next == "right":
        dead("You opened the door and walked off a cliff. Goodbye!")
    else:
        print "I didn't quite catch that."

def right_room():
    print "You went right."
    print "There are two doors. straight or right?"
    next == raw_input("> ")

    if next == "right":
        dead("Oops, a tiger just ate you")
    elif next == "straight":
        second_right()
    else:
        "What?!?!?!"

def second_right():
    print "You went straight"
    print "Nice choice."
    print "You have two choices: left or straight"
    next == raw_input("> ")

    if next == "left":
        dead("You just fell 1 million feet to your death.")
    elif next == "straight":
        print "You made it out alive!"
        exit(0)
    else:
        "WTF?"

def dead(reason):
    print reason, "good job!"
    exit(0)

def start():
    print "You are about to enter a room."
    bear_room()

start()

1 个答案:

答案 0 :(得分:10)

看起来您正在尝试分配next变量,但您使用了相等检查运算符(==)。

相关问题