I tried this code at the interpreter prompt:
>>> x = 7
>>> if x > 5:
... print("five")
I got this error message:
File "<stdin>", line 2
print("five")
IndentationError: expected an indented block
Why?
I tried this code at the interpreter prompt:
>>> x = 7
>>> if x > 5:
... print("five")
I got this error message:
File "<stdin>", line 2
print("five")
IndentationError: expected an indented block
Why?
In the shell you should do this:
>>> if x > 5:
... print("five")
That is, add an indent block after the ":"
Indentation is important in Python. You need to indent your print
statement with a few spaces or a tab otherwise the interpreter will think your if
is empty.
>>> if x > 5:
... print("five")