easy +5 pts

Leap Year Checker

Determine if a given year is a leap year using clear rules.

Write a function `is_leap_year(year)` that takes an integer `year` (e.g., 2024) and returns `True` if it is a leap year and `False` otherwise. A year is a leap year if it is divisible by 4, except that if it is divisible by 100 it is not a leap year, unless it is also divisible by 400. For example, 2000 is a leap year, but 1900 is not.

Constraints

The input `year` is an integer between 1 and 10^9 (inclusive). No negative years or zero. The function should return a boolean value.

Example

>>> is_leap_year(2020)
True
>>> is_leap_year(1900)
False
>>> is_leap_year(2000)
True
>>> is_leap_year(2021)
False
5 points ~5 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Think about the divisibility rules using the modulo operator (%) and the order of checks.
If a year is not divisible by 4, it is definitely not a leap year.
Years divisible by 100 are not leap years unless they are also divisible by 400.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.