Elif problem, help


#1

This is my code.

elif answer == "go up staircase" or answer == "staircase":

What's wrong with it? It keeps on giving me an error:
File "", line 8
elif answer == "go up staircase" or answer == "staircase":
^
SyntaxError: invalid syntax

Please help, if you can.


#2

Is this your full code? If it's not, share your full code and format it using an icon that looks like this: </>.


#3

No, just part of it. I just need help with that particular section.


#4

That particular line on its own doesn't seem to pose any syntax error to me. Therefore there must be another area that might have caused this error message. Hence why more information (code) is probably best to see what's really going on.


#5

Okay. here's the full...

def house():
    print("Greetings and welcome! Please input your player name.")
    name = input("name: ")
    print("Your difficulty is based on how you play. Text based games are for people with a visual imagination, so there really is no difficulty.")
    print("The game begins. You're in a mansion, and your family seems to have left. There is a fireplace lit up. There is a staircase, and oddly, there is a crack in the fireplace, just under the fire. ")
    if answer == "look around" or answer == "look":
        print("You look around and you see a lantern on a table. Along with it, there is 2 oil jars each filled half way with oil.")
elif answer == "go up staircase" or answer == "staircase":
        print("You go up the staircase and you see two doors. Try the first door or the second door?")
        def staircase():
            if answer == "first door" or answer == "first":

                    key=["key"]


if (name in key):
  print "I have the "+key+", I will unlock the first door."
elif (name in enemies):
  print "I don't have the "+key+", so I don't have the ability to open this locked door."
else:
  print "Key? I didn't find a "+key+". I have to go find it."
            elif answer == "second door" or answer == "second":
                print "You go into the room. You see a key on the desk along with a tinderbox. "
    else:
        print ("Pick a different answer...")
        staircase()

staircase()
        else:
            print ("Please pick a different answer.")
        def #():
    if answer == "#" or answer == "#":
    elif answer == "#" or answer == "#":
    else:
        print ("")
        #()

#()
    elif answer == "go in the cavehole" or answer == "go in":
        print ("You almost fall to your death! Luckily, you survive that steep fall.")
    else:
        print ("Great, you've confused the game, now choose what answers are given to you! >:D")
house()

#6

did you post your code correctly? Indention looks pretty off at some places


#7

Post my code correctly? Uhm....


#8

I agree with @stetim94. Your indentation for that line is off. I fixed that indentation somewhere else and error is gone (but others will pop up due to poor indentations in other areas).


edit:
I'm looking at other areas of the code now.


#9

Really? Okay. I'll try fixing the indentation somewhere else, then.
Thanks for help.


#10

Looking more into the code and cleaning some things up, are you using Python 3? If so, please make sure all print statements have parenthesis around them. Especially those in the staircase() function. No need for parenthesis around conditional statements.

You also have undefined variables: answer, enemies.
I cleaned a bit up for you here: link
But, I'm not sure what to do with missing parts so that part is up to you.


#11

I'm looking into it. I needed help because I NEED to do this today.


#12

You can check out the link I provided to help you (with indents and other syntax issues). It's just a cleaned up version of your code. I added answer and enemies as random placeholders though.


#13

Thanks man!!! I love this, I will make slight adjustments if I have to in the placeholders. This looks easier for me now.


#14

I'm using codecademy labs! But CCL does use python 2.7.2


#15

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.