2
2
Find the area of various geometric shapes
3
3
"""
4
4
from math import pi
5
- from typing import Union
6
5
7
6
8
- def surface_area_cube (side_length : Union [ int , float ] ) -> float :
7
+ def surface_area_cube (side_length : float ) -> float :
9
8
"""
10
9
Calculate the Surface Area of a Cube.
11
10
@@ -14,7 +13,7 @@ def surface_area_cube(side_length: Union[int, float]) -> float:
14
13
>>> surface_area_cube(3)
15
14
54
16
15
"""
17
- return 6 * pow ( side_length , 2 )
16
+ return 6 * side_length ** 2
18
17
19
18
20
19
def surface_area_sphere (radius : float ) -> float :
@@ -28,10 +27,10 @@ def surface_area_sphere(radius: float) -> float:
28
27
>>> surface_area_sphere(1)
29
28
12.566370614359172
30
29
"""
31
- return 4 * pi * pow ( radius , 2 )
30
+ return 4 * pi * radius ** 2
32
31
33
32
34
- def area_rectangle (length , width ) :
33
+ def area_rectangle (length : float , width : float ) -> float :
35
34
"""
36
35
Calculate the area of a rectangle
37
36
@@ -41,17 +40,17 @@ def area_rectangle(length, width):
41
40
return length * width
42
41
43
42
44
- def area_square (side_length ) :
43
+ def area_square (side_length : float ) -> float :
45
44
"""
46
45
Calculate the area of a square
47
46
48
47
>>> area_square(10)
49
48
100
50
49
"""
51
- return pow ( side_length , 2 )
50
+ return side_length ** 2
52
51
53
52
54
- def area_triangle (base , height ) :
53
+ def area_triangle (base : float , height : float ) -> float :
55
54
"""
56
55
Calculate the area of a triangle
57
56
@@ -61,7 +60,7 @@ def area_triangle(base, height):
61
60
return (base * height ) / 2
62
61
63
62
64
- def area_parallelogram (base , height ) :
63
+ def area_parallelogram (base : float , height : float ) -> float :
65
64
"""
66
65
Calculate the area of a parallelogram
67
66
@@ -71,7 +70,7 @@ def area_parallelogram(base, height):
71
70
return base * height
72
71
73
72
74
- def area_trapezium (base1 , base2 , height ) :
73
+ def area_trapezium (base1 : float , base2 : float , height : float ) -> float :
75
74
"""
76
75
Calculate the area of a trapezium
77
76
@@ -81,14 +80,14 @@ def area_trapezium(base1, base2, height):
81
80
return 1 / 2 * (base1 + base2 ) * height
82
81
83
82
84
- def area_circle (radius ) :
83
+ def area_circle (radius : float ) -> float :
85
84
"""
86
85
Calculate the area of a circle
87
86
88
87
>>> area_circle(20)
89
88
1256.6370614359173
90
89
"""
91
- return pi * pow ( radius , 2 )
90
+ return pi * radius ** 2
92
91
93
92
94
93
def main ():
0 commit comments