Skip to content

Commit ca82ab2

Browse files
add leap year
1 parent f4cd167 commit ca82ab2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

maths/leap_year.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
https://en.wikipedia.org/wiki/Leap_year
3+
"""
4+
5+
6+
def is_leap_year(year: int) -> bool:
7+
"""
8+
>>> all(is_leap_year(year) for year in [1600, 2000, 24000])
9+
True
10+
>>> all(is_leap_year(year) for year in [1999, 2001, 2002])
11+
False
12+
"""
13+
return year % 4 == 0 and year % 100 != 0 or year % 400 == 0
14+
15+
16+
if __name__ == "__main__":
17+
from doctest import testmod
18+
19+
testmod()

0 commit comments

Comments
 (0)