IndentationError

Example 01 – IndentationError: expected an indented block

lucky_number = 3
msg = 'Good Job!'
if lucky_number > 0:
print msg 

Reason: We did not indent the statement print msg as expected after the if-statement. The print statement should have an indentation.

Example 02- IndentationError: unindent does not match any outer indentation level

lucky_number = 3
msg = 'Good Job!'
if lucky_number > 0:
    print msg
  print lucky_number

Reason: The indentation error happened because the student decreased the indentation in the second print-statement to a level that does not match the other code. The statement print lucky_number should either be at the same indentation as print msg (and be inside the if block) or at the same indentation as the if statement (and be outside the if block).

Example 03 – IndentationError: unexpected indent

lucky_number = 3
msg = 'Good Job!'
if lucky_number > 0:
    print msg
        print lucky_number

Reason: The student added indentation before typing print lucky_number. This is an unexpected indentation. Only add indentation after a def, if, else, elif, while, or for statements (or any statement that ends with a colon.)