Reputation: 3
I'm a complete beginner, I apologize for the incorrect terms So I started that OpenClassroom course on Python and tried to copy this code:
>>> a = 5
>>> if a > 0: # Si a est positif
... print("a est positif.")
... if a < 0: # a est négatif
... print("a est négatif.")
but when I tried it:
>>> a = 5
>>> if a > 0:
... print("a est positif.")
... if a < 0:
File "<stdin>", line 3
if a < 0:
^
SyntaxError: invalid syntax
>>>
after pressing the enter key after the second "if" condition it didn't let me write the instruction and only displayed the error. Any thoughts?
Upvotes: 0
Views: 107
Reputation: 532238
In the interactive interpreter, a compound statement isn't terminated until you enter an empty line. In this case, it means your second if
is a misindented part of the first if
statement.
In a regular script, there is no problem; the compound statement ends as soon as a line without the required indentation is discovered.
Upvotes: 1