-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patharea.py
More file actions
executable file
·50 lines (40 loc) · 828 Bytes
/
area.py
File metadata and controls
executable file
·50 lines (40 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def circle_area(radius: float) -> float:
"""
>>> circle_area(10)
314.1592653589793
>>> circle_area(0)
0.0
"""
import math
return math.pi * radius * radius
def rectangle_area(length: float, width: float) -> float:
"""
>>> rectangle_area(3, 4)
12
>>> rectangle_area(3, 0)
0
>>> rectangle_area(0, 4)
0
"""
return length * width
def square_area(length: float) -> float:
"""
>>> square_area(4)
16
>>> square_area(0)
0
"""
return length ** 2
def triangle_area(length: float, height: float) -> float:
"""
>>> triangle_area(3, 4)
6.0
>>> triangle_area(3, 0)
0.0
>>> triangle_area(0, 4)
0.0
"""
return length * height / 2
if __name__ == "__main__":
from doctest import testmod
testmod()