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")
7 Respuestas
+ 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
+ 2
Your program will print "Leap year" if and only if your year will be divisible by 4.
+ 2
Here is a solution using if/else statements, and it works correctly.
https://code.sololearn.com/cCSu3kJ6F0vV/?ref=app
0
With your code the year 2008 will print what? I think it will do the second else.
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.
0
For Leap Year :
Condition:
Year % 100 != 0
- 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")