25 XP

35. Leap year

Beginner conditions math

Most years have 365 days, but a leap year has 366: February gets a 29th day. Which years are leap years follows a rule in three parts:

  • a year that divides evenly by 4 is a leap year,
  • except a year that divides evenly by 100, which isn't,
  • except a year that divides evenly by 400, which is after all.

So 2024 is a leap year, 1900 isn't (it divides by 100), and 2000 is (it divides by 400).

Write a function is_leap(year) that takes a whole number year and returns True if it is a leap year, or False if it isn't.

Example 1

Inputyear = 2024
OutputTrue
Explanation2024 divides by 4 but not by 100.

Example 2

Inputyear = 1900
OutputFalse
Explanation1900 divides by 100 but not by 400.

Example 3

Inputyear = 2000
OutputTrue
Explanation2000 divides by 400.

Constraints

  • year is a whole number from 1 to 9999.

Submit also runs 9 more tests you can't see.

Practises Booleans and Comparisons (lesson 7).

Code
def is_leap(year):
    """Check whether a year is a leap year.

    year: int, from 1 to 9999
    Returns: bool, True for a leap year, else False
    """
    # Write your code here
    pass