0

Help solving "Leap Year" code in beginner's python

I went with this but it keeps failing at the second output test. I can tell that something isn't correct, but I'm unsure of how to edit it. year = int(input()) if year % 4 == 0 and year % 100 != 0: if year % 400: print("leap year") else: print("not a leap year") else: print("not a leap year")

26th Jun 2021, 3:13 AM
Isabella
3 Answers
+ 3
if not year % 400 or (not year % 4 and year % 100): print("leap year") else: print("not a leap year")
26th Jun 2021, 3:27 AM
visph
visph - avatar
+ 1
To check whether a year is a leap year or not, you need to check the following: 1) If the year is evenly divisible by 4, go to step 2. Otherwise, the year is NOT leap year. 2) If the year is evenly divisible by 100, go to step 3. Otherwise, the year is a leap year. 3) If the year is evenly divisible by 400, the year is a leap year. Otherwise, it is not a leap year. you must print out exactly: print("Leap year") or print("Not a leap year") also read out explanation again. there is no and /or in the if statements
26th Jun 2021, 4:21 AM
Shadoff
Shadoff - avatar
+ 1
Managed to solve it thanks to ppl's help here. Thank you guys!
28th Jun 2021, 2:26 AM
Isabella