-
Notifications
You must be signed in to change notification settings - Fork 0
/
Perimeter_Calculator.py
58 lines (51 loc) · 1.89 KB
/
Perimeter_Calculator.py
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
51
52
53
54
55
56
57
58
"""Python CMD program, object-oriented shape class and subclasses, enter the shape's name, color and other attributes
to construct them and calculate the area and perimeter.
using Python version 3.11.4
@version : 1.0
@license: MIT License
@author : Arman Azarnik
contact me at : armanazarnik@gmail.com
"""
import math
from Circle import Circle
from Triangle import Triangle
from Rectangle import Rectangle
from Square import Square
class Perimeter_Calculator:
"""
Get_perimeter class for calculating the perimeter of different geometric shapes.
"""
def get_Perimeter(Shape):
"""
function for calculating the perimeter of different geometric shapes.
@param Shape: a geometric shape
@type Shape: Shape object
@return: calculated_Perimeter
@rtype: double or string
@examples:
circle_1 = new Circle(3)
triangle_1 = new Triangle(2, 3, 4)
rectangle_1 = new Rectangle(4, 6)
square_1 = new Square(5)
>>> get_Perimeter(circle_1)
18.84955592153876
>>> get_Perimeter(triangle_1)
9.0
>>> get_Perimeter(rectangle_1)
20.0
>>> get_Perimeter(square_1)
20.0
"""
calculated_Perimeter = 0.0
if (isinstance(Shape, Circle)):
calculated_Perimeter = Circle.get_radius(Shape) * 2 * math.pi
elif (isinstance(Shape, Triangle)):
a, b, c = Triangle.get_sides(Shape)
calculated_Perimeter = a + b + c
elif (isinstance(Shape, Rectangle)):
calculated_Perimeter = (Rectangle.get_lenght(Shape) + Rectangle.get_width(Shape)) * 2
elif (isinstance(Shape, Square)):
calculated_Perimeter = Square.get_lenght(Shape) * 4
else:
calculated_Perimeter = "Shape not defiend"
return calculated_Perimeter