Introduction
A leap year (in the Gregorian calendar) occurs:
-In every year that is evenly divisible by 4.
-Unless the year is evenly divisible by 100, in which case it's only a leap year if the year is also evenly divisible by 400.
In my head the conditions for a leap year are:
when it's evenly divisible by 4
OR
when it's evenly divisible by 100 AND 400
Am I not getting this introduction right? I'm french canadian so maybe I'm just not reading this right because I can't seem to complete the task. Here's my code;
def leap_year(year):
return year % 4 == 0 or year % 100 == 0 and year % 400 == 0
The actual solution is:
def leap_year(year):
return year % 4 == 0 and year % 100 != 0 or year % 400 == 0
Which in my head translate to the year has to be evenly divisible by 4 but not 100, or evenly by 400 only. I feel dumb, can somebody explain this to me ahah?