22Find the area of various geometric shapes
33"""
44from math import pi
5- from typing import Union
65
76
8- def surface_area_cube (side_length : Union [ int , float ] ) -> float :
7+ def surface_area_cube (side_length : float ) -> float :
98 """
109 Calculate the Surface Area of a Cube.
1110
@@ -14,7 +13,7 @@ def surface_area_cube(side_length: Union[int, float]) -> float:
1413 >>> surface_area_cube(3)
1514 54
1615 """
17- return 6 * pow ( side_length , 2 )
16+ return 6 * side_length ** 2
1817
1918
2019def surface_area_sphere (radius : float ) -> float :
@@ -28,10 +27,10 @@ def surface_area_sphere(radius: float) -> float:
2827 >>> surface_area_sphere(1)
2928 12.566370614359172
3029 """
31- return 4 * pi * pow ( radius , 2 )
30+ return 4 * pi * radius ** 2
3231
3332
34- def area_rectangle (length , width ) :
33+ def area_rectangle (length : float , width : float ) -> float :
3534 """
3635 Calculate the area of a rectangle
3736
@@ -41,17 +40,17 @@ def area_rectangle(length, width):
4140 return length * width
4241
4342
44- def area_square (side_length ) :
43+ def area_square (side_length : float ) -> float :
4544 """
4645 Calculate the area of a square
4746
4847 >>> area_square(10)
4948 100
5049 """
51- return pow ( side_length , 2 )
50+ return side_length ** 2
5251
5352
54- def area_triangle (base , height ) :
53+ def area_triangle (base : float , height : float ) -> float :
5554 """
5655 Calculate the area of a triangle
5756
@@ -61,7 +60,7 @@ def area_triangle(base, height):
6160 return (base * height ) / 2
6261
6362
64- def area_parallelogram (base , height ) :
63+ def area_parallelogram (base : float , height : float ) -> float :
6564 """
6665 Calculate the area of a parallelogram
6766
@@ -71,7 +70,7 @@ def area_parallelogram(base, height):
7170 return base * height
7271
7372
74- def area_trapezium (base1 , base2 , height ) :
73+ def area_trapezium (base1 : float , base2 : float , height : float ) -> float :
7574 """
7675 Calculate the area of a trapezium
7776
@@ -81,14 +80,14 @@ def area_trapezium(base1, base2, height):
8180 return 1 / 2 * (base1 + base2 ) * height
8281
8382
84- def area_circle (radius ) :
83+ def area_circle (radius : float ) -> float :
8584 """
8685 Calculate the area of a circle
8786
8887 >>> area_circle(20)
8988 1256.6370614359173
9089 """
91- return pi * pow ( radius , 2 )
90+ return pi * radius ** 2
9291
9392
9493def main ():
0 commit comments