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.

17th Sep 2021, 1:31 AM
Riccardo
10 ответов
+ 3
Here's a tutorial about Python code indentation https://code.sololearn.com/cT5BRIbkia21/?ref=app
17th Sep 2021, 2:51 AM
Ipang
+ 1
you need an if condition first. please post the full code in the playground and link it here
17th Sep 2021, 1:39 AM
Slick
Slick - avatar
+ 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.
17th Sep 2021, 1:48 AM
Slick
Slick - avatar
+ 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
18th Sep 2021, 9:41 PM
Andrew Turvey
+ 1
Thanks for the replies. I sorted it in the end. Indentation and line up is important!
18th Sep 2021, 10:24 PM
Riccardo
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")
17th Sep 2021, 1:45 AM
Riccardo
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?
17th Sep 2021, 2:31 AM
Riccardo
0
Code tab > new code
17th Sep 2021, 2:41 AM
Slick
Slick - avatar
0
Thanks.
17th Sep 2021, 2:43 AM
Riccardo
0
If and elif indentation is not required. If, elif and else should be in same level.
17th Sep 2021, 3:43 AM
Parith (Faree)
Parith (Faree) - avatar