Simple if statement on python interpreter

christianbueno.1 picture christianbueno.1 · Dec 16, 2017 · Viewed 8.3k times · Source

Environment:

  • Fedora 27 (GNU/Linux)
  • terminal
  • python3.6.3

I am having problems running this simple lines of code in the python interpreter, this is an only if statement or alone if statement.

n = 5
if n == 4:
    print('n=4')
print('done')

enter image description here

This must print the word "done", but what am I doing wrong?

Answer

Brett Beatty picture Brett Beatty · Dec 16, 2017

The interpreter gives you a line after blocks to leave blank for the interpreter to know your block is over (or to put an else, etc.). Putting something there makes it freak out. Just leave it that line blank and wait for the next >>> before your print('done').

>>> n = 5
>>> if n == 4:
...    print('n=4')
...
>>> print('done')
done