diff --git a/solutions/python/leap/2/leap.py b/solutions/python/leap/2/leap.py new file mode 100644 index 0000000..2930657 --- /dev/null +++ b/solutions/python/leap/2/leap.py @@ -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)