-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharoon shapes.py
127 lines (93 loc) · 3.9 KB
/
haroon shapes.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from math import pi, sqrt
class Canvas:
def __init__(self, height, width):
self.height = height
self.width = width
def __str__(self):
return f'Canvas Dimensions: {self.height} by {self.width}\n'
class Outline:
def __init__(self):
self.outline_width = 2
self.outline_color = "Black"
class Shape:
def __init__(self, name, background):
self.name = name
self.background = background
def perimeter(self):
pass
def area(self):
pass
class Square(Shape, Outline):
def __init__(self, name, background, length):
super().__init__(name, background)
Outline.__init__(self)
self.length = length
def area(self):
return self.length * self.length
def perimeter(self):
return 4 * self.length
def __str__(self):
return f'Shape: {self.name}, Length: {self.length}, Outline Width & Color: {self.outline_width} / {self.outline_color}\nBackground: {self.background}, Area: {self.area()}, Perimeter: {self.perimeter()}\n'
class Rectangle(Shape, Outline):
def __init__(self, name, background, length, width):
super().__init__(name, background)
Outline.__init__(self)
self.length = length
self.width = width
def area(self):
return self.length * self.width
def perimeter(self):
return 2 * self.length + 2 * self.width
def __str__(self):
return f'Shape: {self.name}, Length: {self.length}, Width: {self.width}\nOutline Width & Color: {self.outline_width} / {self.outline_color}\nBackground: {self.background}, Area: {self.area()}, Perimeter: {self.perimeter()}\n'
class Circle(Shape, Outline):
def __init__(self, name, background, radius):
super().__init__(name, background)
Outline.__init__(self)
self.radius = radius
def area(self):
return self.radius ** 2 * pi
def circumference(self):
return 2 * pi * self.radius
def __str__(self):
return f'Shape: {self.name}, Radius: {self.radius}\nOutline Width & Color: {self.outline_width} / {self.outline_color}\nArea: {self.area()}, Circumference: {self.circumference()}\n'
class Oval(Shape, Outline):
def __init__(self, name, background, radius1, radius2):
super().__init__(name, background)
Outline.__init__(self)
self.radius1 = radius1
self.radius2 = radius2
def area(self):
return pi * self.radius1 * self.radius2
def circumference(self):
return 2 * pi * sqrt((self.radius1 ** 2 + self.radius2 ** 2) / 2)
def __str__(self):
return f'Shape: {self.name}, Radius1: {self.radius1}, Radius2: {self.radius2}\nOutline Width & Color: {self.outline_width} / {self.outline_color}\nArea: {round(self.area(), 2)}, Circumference: {round(self.circumference(), 2)}\n'
class Triangle(Shape, Outline):
def __init__(self, name, background, height, base):
super().__init__(name, background)
Outline.__init__(self)
self.height = height
self.base = base
def area(self):
return 0.5 * self.base * self.height
def perimeter(self, a, b, c):
print(f'Perimeter: {a + b + c}')
def __str__(self):
return f'Shape: {self.name}, Height: {self.height}, Base: {self.base}\nOutline Width & Color: {self.outline_width} / {self.outline_color}\nArea: {self.area()}'
def main():
canvas = Canvas(30, 40)
print(canvas)
square = Square("Square", "Blue", 5)
print(square)
rectangle = Rectangle("Rectangle", "Blue", 5, 10)
print(rectangle)
circle = Circle("Circle", "Red", 7)
print(circle)
oval = Oval("Oval", "Orange", 7, 9)
print(oval)
triangle = Triangle("Triangle", "Yellow", 3, 5)
print(triangle)
triangle.perimeter(1, 2, 3)
if __name__ == '__main__':
main()