0
Else statement syntax error-Python
I keep getting a syntax error on an else statement. I have checked several times and it looks correct. Like this: else: Simple right? What am I doing wrong. It is in the Leap year exercise early on in the course.
10 ответов
+ 3
Here's a tutorial about Python code indentation
https://code.sololearn.com/cT5BRIbkia21/?ref=app
+ 1
you need an if condition first.
please post the full code in the playground and link it here
+ 1
they all need to be on the same indentation level. each elif and else line. why do you keep indenting more?
The playground is where you can run code here and also save it so you can send pwople links to view and run. Cause you shouldn't make people who want to help copy and paste your code.
+ 1
Proper indentation is
If ...
Command
Elif ...:
Commands
Else:
Commands
Commands not subject to if
ie. keep "if" "else" and "elif" at the same level of indentation
+ 1
Thanks for the replies. I sorted it in the end. Indentation and line up is important!
0
I’m not sure what “the playground is”. Here is the latest bit of code I have tried. I get the same error whatever I do. Syntax error line 3
year = int(input())
if (year % 4 == 0):
elif (year % 100 == 0):
elif (year % 400 == 0):
print ("Leap year")
else:
print ("Not a leap year")
0
I’ve tried every possible combination of if else and elif statements with and without indents. It is always line 3 giving a syntax error.
How do I find the playground?
0
Code tab > new code
0
Thanks.
0
If and elif indentation is not required. If, elif and else should be in same level.