easy +7 pts

Leap Years in Range

Given a range of years, return all the leap years in order.

Write a function `leap_years_in_range(start_year, end_year)` that returns a list of all leap years from `start_year` to `end_year` inclusive, in ascending order. Use the standard Gregorian calendar rules: a year is a leap year if it is divisible by 4, except that years divisible by 100 are not leap years unless they are also divisible by 400. For example, 2000 is a leap year, but 1900 is not. You may assume `start_year <= end_year`.

Constraints

1 <= start_year <= end_year <= 9999. The output list may be empty if there are no leap years in the range.

Example

>>> leap_years_in_range(2000, 2020)
[2000, 2004, 2008, 2012, 2016, 2020]
>>> leap_years_in_range(1899, 1901)
[]
7 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

A simple loop over the years is sufficient.
Remember the 400-year exception: 2000 is a leap year even though it is divisible by 100.
Use a list comprehension or a loop with an append.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.