-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshapes.py
62 lines (46 loc) · 1.43 KB
/
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
from abc import ABC, abstractmethod
import math
class Polygon():
def __init__(self, length, width):
self.__length = length
self.__width = width
@abstractmethod
def area(self):
pass
@abstractmethod
def perimeter(self):
pass
class Rectangle(Polygon):
def __init__(self, length, width):
self.__length = length
self.__width = width
def area(self):
return self.__length * self.__width
def perimeter(self):
return (2 * self.__length) + (2 * self.__width)
class Square(Rectangle):
def __init__(self, length):
self.__length = length
self.__width = length
def area(self):
return self.__length * self.__width
def perimeter(self):
return (2 * self.__length) + (2 * self.__width)
class RightTriangle(Polygon):
def __init__(self, length, width):
self.__length = length
self.__width = width
def area(self):
return (self.__length * self.__width) / 2
def perimeter(self):
return self.__length + self.__width + math.sqrt((self.__length * self.__length) + (self.__width * self.__width))
print("testing")
rect = Rectangle(2, 3)
print(rect.area())
print(rect.perimeter())
square = Square(4)
print(square.area())
print(square.perimeter())
triangle = RightTriangle(3,4)
print(triangle.area())
print(triangle.perimeter())