← Back to challenges

Is It a Leap Year?

PythonHardalgorithmsmathnumbersvalidation

Instructions

In a calendar year, it is exactly 365.25 days. But, eventually, this will lead to confusion because humans normally count by exact divisibility of 1 and not with decimal points. So, to avoid the latter, it was decided to add up all 0.25 days every four-year cycle and give that year 366 days (including February 29 as an intercalary day) and call it a leap year. The other three years in the four-year cycle would only contain 365 days and wouldn't be leap years.

In this challenge, though quite repetitive, we'll take it to a new level, where you are to determine if it's a leap year or not without the use of the datetime class, if blocks, if-elif blocks, or conditionals (a if b else c). You also may not use the logical operators AND (and) or OR (or), with the exemption of the NOT (not) operator.

Return True if it's a leap year, False otherwise.

Examples

leap_year(1979) ➞ False

leap_year(2000) ➞ True

leap_year(2016) ➞ True

leap_year(1521) ➞ False

leap_year(1996) ➞ True

leap_year(1800) ➞ False

Notes

You can't use the datetime class, if statements in general, the conditional, or the logical operators (and, or).

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.