0

Python Leap Year

#The test case is passing 4/6. I don't know what is wrong with my code, please help year = int(input()) if year % 4 == 0: if year % 100 == 0: if year % 400 == 0: print("Leap year") else: print("Not a leap year") else: print("Not a leap year") else: print("Not a leap year")

30th May 2021, 6:29 PM
Adilet Kambarov
Adilet Kambarov - avatar
7 Antworten
+ 3
I think your algorithm is wrong. A leap year is divisible by 4 but not if divisible by 100 unless also divisible by 400. See https://code.sololearn.com/cOgB9UfjI1vp
30th May 2021, 7:01 PM
David Ashton
David Ashton - avatar
+ 2
Your program will print "Leap year" if and only if your year will be divisible by 4.
30th May 2021, 7:00 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
+ 2
Here is a solution using if/else statements, and it works correctly. https://code.sololearn.com/cCSu3kJ6F0vV/?ref=app
30th May 2021, 9:31 PM
Jan
Jan - avatar
0
With your code the year 2008 will print what? I think it will do the second else.
30th May 2021, 6:50 PM
Paul
Paul - avatar
0
Your code only prints "Leap year" if all three conditions are met. I.e. only years that can be divided by 4 and 100 and 400 are recognised as leap years.
30th May 2021, 8:58 PM
Simon Sauter
Simon Sauter - avatar
0
For Leap Year : Condition: Year % 100 != 0
1st Jun 2021, 6:38 PM
Tejas Raut
- 1
year = int(input()) if(year%4 == 0): if(year%100 == 0): if(year%400 == 0): print("Leap year") else: print("Not a leap year") else: print("Leap year") else: print ("Not a leap year")
2nd Jan 2022, 7:54 AM
Roaa Qteishat
Roaa Qteishat - avatar