Python - I get an indented error, but I don't see it. Tabs and spaces don't mix

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 not a valid answer." 

and error:

 line 97 else: ^ IndentationError: expected an indented block 

I have absolutely no idea why I am getting this error, but maybe you guys can help me. There are many if / else / elif arguments that can confuse me. Any help is much appreciated, thanks!

EDIT: Adding a "pass" or code to an elif statement simply wraps the same error on line 95.

+4
source share
2 answers

Try the following:

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

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

+14
source

Besides the pass requirement, it is 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 not a valid answer." # space space tab tab tab 

You have a mixture.

In vim you can do this:

 set listchars=tab:>-,trail:. 

And here is what your code looks like:

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

Source: https://habr.com/ru/post/1486678/


All Articles