4

私は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()
4

1 に答える 1

10

変数に割り当てようとしているようですがnext、等値チェック演算子 ( ==) を使用しています。

于 2013-07-16T23:30:18.627 に答える