Skip to content

Commit fc48c4e

Browse files
Merge pull request #10 from examplehub/dev
development
2 parents 8ef2c65 + 9f24a19 commit fc48c4e

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

maths/area.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def circle_area(radius: float) -> float:
2+
"""
3+
>>> circle_area(10)
4+
314.1592653589793
5+
>>> circle_area(0)
6+
0.0
7+
"""
8+
import math
9+
10+
return math.pi * radius * radius
11+
12+
13+
if __name__ == "__main__":
14+
from doctest import testmod
15+
16+
testmod()

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()

maths/sum_to_n.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def sum_to_n(n: int) -> int:
2+
"""
3+
>>> sum_to_n(100)
4+
5050
5+
>>> sum_to_n(10)
6+
55
7+
"""
8+
return sum(i for i in range(1, n + 1))
9+
10+
11+
if __name__ == "__main__":
12+
from doctest import testmod
13+
14+
testmod()

0 commit comments

Comments
 (0)