Checking leap year

Use positive integer years in the Gregorian calendar.

Write a function that takes a year as input and returns "Leap Year" if it’s a leap year and "Not a Leap Year" if it’s not.

A year is a leap year when it is divisible by 4, except for years divisible by 100, which are leap years only when they are also divisible by 400.

Complete Listing 1. Save the completed code as check_leap_year.py and run it to check the supplied assertions.

Listing 1: Starter function and checks for check_leap_year.
def check_leap_year(year: int) -> str:
    raise NotImplementedError("Replace this line with your code.")


# Divisible by 4
got = check_leap_year(2020)
assert got == "Leap Year", f"2020: expected 'Leap Year', got {got!r}"

# Not divisible by 4
got = check_leap_year(2023)
assert got == "Not a Leap Year", f"2023: expected 'Not a Leap Year', got {got!r}"

# Divisible by 100 and by 400: a leap year after all
got = check_leap_year(2000)
assert got == "Leap Year", f"2000: expected 'Leap Year', got {got!r}"

# Divisible by 100 but not by 400: the exception most often missed
got = check_leap_year(1900)
assert got == "Not a Leap Year", f"1900: expected 'Not a Leap Year', got {got!r}"

# Your case: which year is most likely to break it?
# got = check_leap_year(___)
# assert got == "___", f"___: expected '___', got {got!r}"
  • assert condition checks a Boolean condition. A true condition produces no output; a false condition raises AssertionError. For example, assert 2 + 3 == 5 passes.
  • a % b returns the remainder after division by nonzero b. For example, 7 % 3 is 1, and 12 % 4 is 0.