Leap Year Checker

Easy ⏱ 8 min 82% acceptance ★★★★☆ 4.4
Write a function is_leap_year(year) that returns True if year is a leap year and False otherwise. A year is a leap year if it is divisible by 4, except centuries (divisible by 100), which must also be divisible by 400.

Examples

Example 1
Input
is_leap_year(2024)
Output
True
Explanation

2024 is divisible by 4 and not a century year.

Example 2
Input
is_leap_year(1900)
Output
False
Explanation

1900 is divisible by 100 but not by 400.

Example 3
Input
is_leap_year(2000)
Output
True
Explanation

2000 is divisible by 400.

Constraints

  • year is a positive integer.

Topics

Conditional Statementsnested conditionals

Companies

MicrosoftCognizant

Hints

Hint 1

Handle the divisible-by-100 exception before the divisible-by-4 rule.

Hint 2

The divisible-by-400 rule overrides the century exception.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.