Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Learn python the hard way - exercise 36 function problems

Tags:

python

I'm learning to code through learn python the hard way, and I've recently gotten stuck for the first time. For this exercise we're supposed to write our own game. I did so, but for some reason whenever I run it the right_room() function exits after I put in an answer, instead of proceeding to the next room. Any help would be greatly appreciated. Here's my code:

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()
like image 289
user2589342 Avatar asked Dec 27 '22 00:12

user2589342


1 Answers

It looks like you're trying to assign to the next variable, but you used the equality check operator (==).

like image 162
Vyassa Baratham Avatar answered Jan 12 '23 02:01

Vyassa Baratham