← Back to challenges

Number of Leap Years

PythonHardnumbersdatesstrings

Instructions

Given a range of years as a string, return the number of leap years there are within the range (inclusive).

Examples

num_of_leapyears("1980-1984") ➞ 2
# 1980 and 1984 are leapyears.

num_of_leapyears("2000-2020") ➞ 6

num_of_leapyears("1600-2000") ➞ 98

Notes

  • Remember that a hyphen separates the years.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Standard Deviation