From 2a54ed4bc3a81a2f2b5a0385bead71e967d98293 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Thu, 9 Jan 2025 22:08:50 +0200 Subject: [PATCH] edits --- solutions/leap_year.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 solutions/leap_year.py diff --git a/solutions/leap_year.py b/solutions/leap_year.py new file mode 100644 index 000000000..3f1cd90c9 --- /dev/null +++ b/solutions/leap_year.py @@ -0,0 +1,31 @@ +""" +The module checks whether a given year is a leap year. + +A year is a leap year if it is divisible by 4, +and if it is divisible by 100, it must also be divisible by 400. +""" + +def leap_year(year: int) -> bool: + """ + Checks whether the given year is a leap year. + + Argument: + year, a positive integer + + Returns: + boolean: True if the year is a leap year, false otherwise. + + Examples: + >>> leap_year(2024) + True + >>> leap_year(1900) + False + >>> leap_year(2021) + False + """ + if not isinstance(year, int): + raise ValueError("Year must be an integer") + if year < 0: + raise ValueError("Year must be positive integer") + + return(year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)