Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions solutions/python/leap/2/leap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Solution for Leap exercise."""


def leap_year(year: int) -> bool:
"""
Determine whether a given year is a leap year.

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.

Some examples:

- 1997 was not a leap year as it's not divisible by 4.
- 1900 was not a leap year as it's not divisible by 400.
- 2000 was a leap year!

:param year: any year
:type year: int
:return: whether a given year is a leap year
:rtype: bool
"""
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)