@@ -31,14 +31,14 @@ def surface_area_sphere(radius: float) -> float:
31
31
return 4 * pi * pow (radius , 2 )
32
32
33
33
34
- def area_rectangle (base , height ):
34
+ def area_rectangle (length , width ):
35
35
"""
36
36
Calculate the area of a rectangle
37
37
38
- >> area_rectangle(10,20)
38
+ >>> area_rectangle(10,20)
39
39
200
40
40
"""
41
- return base * height
41
+ return length * width
42
42
43
43
44
44
def area_square (side_length ):
@@ -48,24 +48,24 @@ def area_square(side_length):
48
48
>>> area_square(10)
49
49
100
50
50
"""
51
- return side_length * side_length
51
+ return pow ( side_length , 2 )
52
52
53
53
54
- def area_triangle (length , breadth ):
54
+ def area_triangle (base , height ):
55
55
"""
56
56
Calculate the area of a triangle
57
57
58
58
>>> area_triangle(10,10)
59
59
50.0
60
60
"""
61
- return 1 / 2 * length * breadth
61
+ return ( base * height ) / 2
62
62
63
63
64
64
def area_parallelogram (base , height ):
65
65
"""
66
66
Calculate the area of a parallelogram
67
67
68
- >> area_parallelogram(10,20)
68
+ >>> area_parallelogram(10,20)
69
69
200
70
70
"""
71
71
return base * height
@@ -75,8 +75,8 @@ def area_trapezium(base1, base2, height):
75
75
"""
76
76
Calculate the area of a trapezium
77
77
78
- >> area_trapezium(10,20,30)
79
- 450
78
+ >>> area_trapezium(10,20,30)
79
+ 450.0
80
80
"""
81
81
return 1 / 2 * (base1 + base2 ) * height
82
82
@@ -85,24 +85,29 @@ def area_circle(radius):
85
85
"""
86
86
Calculate the area of a circle
87
87
88
- >> area_circle(20)
88
+ >>> area_circle(20)
89
89
1256.6370614359173
90
90
"""
91
- return pi * radius * radius
91
+ return pi * pow ( radius , 2 )
92
92
93
93
94
94
def main ():
95
95
print ("Areas of various geometric shapes: \n " )
96
- print (f"Rectangle: { area_rectangle (10 , 20 )= } " )
97
- print (f"Square: { area_square (10 )= } " )
98
- print (f"Triangle: { area_triangle (10 , 10 )= } " )
99
- print (f"Parallelogram: { area_parallelogram (10 , 20 )= } " )
100
- print (f"Trapezium: { area_trapezium (10 , 20 , 30 )= } " )
101
- print (f"Circle: { area_circle (20 )= } " )
102
- print ("Surface Areas of various geometric shapes: \n " )
103
- print (f"Cube: { surface_area_cube (20 )= } " )
104
- print (f"Sphere: { surface_area_sphere (20 )= } " )
96
+ print (f"Rectangle: { area_rectangle (10 , 20 )} " )
97
+ print (f"Square: { area_square (10 )} " )
98
+ print (f"Triangle: { area_triangle (10 , 10 )} " )
99
+ print (f"Parallelogram: { area_parallelogram (10 , 20 )} " )
100
+ print (f"Trapezium: { area_trapezium (10 , 20 , 30 )} " )
101
+ print (f"Circle: { area_circle (20 )} " )
102
+ print ("\n Surface Areas of various geometric shapes: \n " )
103
+ print (f"Cube: { surface_area_cube (20 )} " )
104
+ print (f"Sphere: { surface_area_sphere (20 )} " )
105
105
106
106
107
107
if __name__ == "__main__" :
108
+
109
+ import doctest
110
+
111
+ doctest .testmod (verbose = True ) # verbose so we can see methods missing tests
112
+
108
113
main ()
0 commit comments