Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 288
Cal Courtney Avatar asked Dec 07 '22 07:12

Cal Courtney


1 Answers

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.

like image 74
Óscar López Avatar answered Jan 14 '23 03:01

Óscar López