Leap year exercise | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Leap year exercise

I've come up with this code for the "leap year" exercise in Python for beginners (23.2) and I can't find why it's not completing all the test cases. I've written different versions of it and it's the ones that hit the closest and looks the most simple and smooth. Only test cases 3 and 4 are not met but they're hidden so I don't know what's the problem... Is it just in front of my eyes and I can't see it? :)) year = int(input()) if (year % 4 == 0) and (year % 100 == 0) and (year % 400 == 0): print("Leap year") else: print("Not a leap year")

23rd Jun 2021, 9:02 AM
Tony Anciaux
Tony Anciaux - avatar
2 Answers
+ 3
your condition is: if (year % 4 == 0) and (year % 100 == 0) and (year % 400 == 0): print("Leap year") It means it must fulfill all these three conditions to become a leap year. That's why even though 4 is a leap year your code will print it's not a leap year. Read the question carefully.
23rd Jun 2021, 9:07 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
OMG I solved it! I feel like a genius, I know it's not the case but it was driving me nuts, I'm so happy right now 😃
23rd Jun 2021, 9:40 AM
Tony Anciaux
Tony Anciaux - avatar