Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this elif statement throwing an error?

Tags:

python

class TheBridge(Scene):

def enter(self):
    print "You burst into the bridge with the bomb"
    print "There are a number of gothons standing about"
    print "and looking scared of the bomb you currently have underneath your arm"
    print "They look nervous about what you are going to do"

    action = raw_input("> ")


    if action == "Throw the bomb":
        print "You throw the bomb at the gorcons on the bridge"
        print "They pure and utter crap themselves and pull out their laser blasters and shhot you dead"
        print "at least the bomb will kill the gorcons, you die a hero"
        return 'death'

    elif action == "Put the bomb down slowly":
        print "You pull you laser blaster from your holster and point it at the bomb"
        print " You very slowly set the bomb on the ground and move backwards"
        print "You then jump back through the door and start firing your gun at the"
        print "lock and you blast it so the gorcons can't escape"
        print "You then procede to try and find an escape pod"
        return 'escape_pod'

    else:    
        print "DOES NOT COMPUTE"
        return "the_bridge"

It's throwing a syntax error for some reason. Maybe I'm a complete idiot and can't see something blindingly obvious. Definitely not the spacing or indentation or anything like that as I have checked that.

Any ideas?

Error Message:

  File "ex43.py", line 131
    elif action == "Put the bomb down slowly":
       ^
SyntaxError: invalid syntax`
like image 500
Strobe_ Avatar asked Nov 19 '25 06:11

Strobe_


1 Answers

You are mixing tabs and spaces (your copied post here certainly does).

Run your code with python -tt and fix any problems that finds.

Preferably, replace all tabs with spaces and configure your editor to do so automatically.

like image 197
Martijn Pieters Avatar answered Nov 20 '25 20:11

Martijn Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!