Cal Courtney
Cal Courtney

Reputation: 1289

Python - I'm getting an indentation error, but I don't see one. Tabs and spaces aren't mixed

My code is:

90              if needinexam > 100:
91                  print "We are sorry, but you are unable to get an A* in this class."
92              else:
93                  print "You need " + final + "% in your Unit 3 controlled assessment to get an A*"
94          
95          elif unit2Done == "n":
96              
97          else:
98              print "Sorry. That's not a valid answer."

and the error is:

line 97
    else:
       ^
IndentationError: expected an indented block

I have absolutely no idea why I'm getting this error, but maybe you guys can help me. There are A LOT of if/else/elif statements around it so that may be confusing me. Any help is greatly appreciated, thank you!

EDIT: Adding "pass" or code into the elif statement just moves the same error to line 95.

Upvotes: 4

Views: 1432

Answers (2)

Izkata
Izkata

Reputation: 9323

Aside from requiring pass, it's right here:

95          elif unit2Done == "n":  # space space tab tab
96              pass # space space space space tab tab tab
97          else: # space space space space tab tab
98              print "Sorry. That's not a valid answer." # space space tab tab tab

You do have a mixture.

In vim, you can do this:

set listchars=tab:>-,trail:.

And this is what your code looks like:

95  >--->---elif unit2Done == "n":
96    >->--->---pass
97    >->---else:
98  >--->--->---print "Sorry. That's not a valid answer."

Upvotes: 1

Óscar López
Óscar López

Reputation: 236004

Try this:

elif unit2Done == "n":
    pass # this is used as a placeholder, so the condition's body isn't empty
else:
    print "Sorry. That's not a valid answer."

The problem here is that the body of the unit2Done == "n" condition can not be empty. In this case, a pass must be used as a kind of placeholder.

Upvotes: 14

Related Questions