Editor

Leap Year

#220 · Python Basics · Beginner · 30 XP · about 4 min

Most years have 365 days, but a leap year has 366: February gets a 29th day. Write is_leap(year) that returns True if year is a leap year and False if it is not.

The calendar uses three rules:

  • A year divisible by 4 is a leap year,
  • except a year divisible by 100, which is not,
  • except a year divisible by 400, which is a leap year after all.

Examples

is_leap(2024)  # returns True
is_leap(1900)  # returns False
is_leap(2000)  # returns True

1900 is divisible by 100 but not by 400, so it was not a leap year. 2000 is divisible by 400, so it was.

Constraints

  • 1 <= year <= 9999

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.