← Back to challenges

Leap Year Function ⌚

PythonMediummathalgebraconditionsvalidation

Instructions

Write a function that returns True if a year is a leap, otherwise return False.

A year is a "leap year" if it lasts 366 days, instead of 365 in a typical year. That extra day is added to the end of the shortest month, creating February 29.

A leap year occurs every four years, and will take place if the year is a multiple of four. The exception to this is a year at the beginning of a century (for example, 1900 or 2000), where the year must be divisible by 400 to be a leap year.

Examples

leap_year(1990) ➞ False

leap_year(1924) ➞ True

leap_year(2021) ➞ False

Notes

  • Do not overthink this challenge.
  • You can solve the problem with a few lines of code.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Even Index Elements in a List