+ 5

What is the answer for the “Leap Year” question

The question asks to print out “not a leap year” or “leap year” for any input of the year. I solved the question by several ways, yet the answers always went wrong. Can somebody help me to debug my code? year = int(input()) #your code goes here 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")

10th May 2021, 7:48 AM
Weitao Sun
Weitao Sun - avatar
10 Réponses
- 3
thanks David Ashton i forgot that 😂😀
10th May 2021, 10:36 AM
Giriraj Yalpalwar
Giriraj Yalpalwar - avatar
+ 2
Er, Thirt13n && and || are not used in Python. Just say "and" and "or".
10th May 2021, 9:43 AM
David Ashton
David Ashton - avatar
+ 1
Hey Weitao Sun Year is a leap year if it is divisible by 4 but not by 100, except that years divisible by 400 are leap years. Therefore your condition will be like this if ((year % 4 == 0 and year % 100 != 0) or year % 400 == 0)
10th May 2021, 8:53 AM
Giriraj Yalpalwar
Giriraj Yalpalwar - avatar
+ 1
n=int(input("enter year:")) if((n%4==0 and n%400==0) or n%100!=0): print(n,"is leap year") else: Print(n,"is not a leap year") #pythoncode
12th May 2021, 4:36 AM
P.Maheswari
0
Weitao Sun. Here is a simple solution https://code.sololearn.com/cOgB9UfjI1vp
10th May 2021, 9:47 AM
David Ashton
David Ashton - avatar
0
I guess this one is simple 😀 https://code.sololearn.com/cQk9jOd1OeU2/?ref=app
11th May 2021, 4:11 AM
Išhwäŕÿā.P 👑
Išhwäŕÿā.P 👑 - avatar
0
This one might not be the simplest solution, but it works as expected in all the test cases. https://code.sololearn.com/cCSu3kJ6F0vV/?ref=app
12th May 2021, 5:26 AM
Jan
Jan - avatar
0
a = int(input()) print("Yes"*(a%4<1 and a%100 or a%400<1) or "No") # Hope this helps
12th May 2021, 6:39 AM
Calvin Thomas
Calvin Thomas - avatar
0
The second else should print "Leap year"
12th May 2021, 8:00 AM
Lychee Li
Lychee Li - avatar
- 2
in the second else statement you should write "leap year"
11th May 2021, 9:30 PM
Feruza Khamidova
Feruza Khamidova - avatar