Skip to content

Commit e6fdcc9

Browse files
consists of area of various geometrical shapes (TheAlgorithms#2002)
* consists of area of various geometrical shapes In this program it consists of various area calculation of different geometrical shapes such as (square,rectangle) and many other shapes. * print(f'Rectangle: {area_rectangle(10, 20)=}') * Update area.py * Areas of various geometric shapes: Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent 77f3888 commit e6fdcc9

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

maths/area.py

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""
2+
Find the area of various geometric shapes
3+
"""
4+
5+
import math
6+
7+
8+
def area_rectangle(base, height):
9+
"""
10+
Calculate the area of a rectangle
11+
12+
>> area_rectangle(10,20)
13+
200
14+
"""
15+
return base * height
16+
17+
18+
def area_square(side_length):
19+
"""
20+
Calculate the area of a square
21+
22+
>>> area_square(10)
23+
100
24+
"""
25+
return side_length * side_length
26+
27+
28+
def area_triangle(length, breadth):
29+
"""
30+
Calculate the area of a triangle
31+
32+
>>> area_triangle(10,10)
33+
50.0
34+
"""
35+
return 1 / 2 * length * breadth
36+
37+
38+
def area_parallelogram(base, height):
39+
"""
40+
Calculate the area of a parallelogram
41+
42+
>> area_parallelogram(10,20)
43+
200
44+
"""
45+
return base * height
46+
47+
48+
def area_trapezium(base1, base2, height):
49+
"""
50+
Calculate the area of a trapezium
51+
52+
>> area_trapezium(10,20,30)
53+
450
54+
"""
55+
return 1 / 2 * (base1 + base2) * height
56+
57+
58+
def area_circle(radius):
59+
"""
60+
Calculate the area of a circle
61+
62+
>> area_circle(20)
63+
1256.6370614359173
64+
"""
65+
return math.pi * radius * radius
66+
67+
68+
def main():
69+
print("Areas of various geometric shapes: \n")
70+
print(f"Rectangle: {area_rectangle(10, 20)=}")
71+
print(f"Square: {area_square(10)=}")
72+
print(f"Triangle: {area_triangle(10, 10)=}")
73+
print(f"Parallelogram: {area_parallelogram(10, 20)=}")
74+
print(f"Trapezium: {area_trapezium(10, 20, 30)=}")
75+
print(f"Circle: {area_circle(20)=}")
76+
77+
78+
if __name__ == "__main__":
79+
main()

0 commit comments

Comments
 (0)