-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriangle.py
More file actions
33 lines (23 loc) · 796 Bytes
/
Triangle.py
File metadata and controls
33 lines (23 loc) · 796 Bytes
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
from math import hypot
class Point:
def __init__(self, x=0.0, y=0.0):
self.__x = x
self.__y = y
def getx(self):
return self.__x
def gety(self):
return self.__y
def distance_from_xy(self, x, y):
return hypot(self.__x - x, self.__y - y)
def distance_from_point(self, point):
return self.distance_from_xy(point.getx(), point.gety())
class Triangle:
def __init__(self, vertice1, vertice2, vertice3):
self.__vertices = [vertice1, vertice2, vertice3]
def perimeter(self):
per = 0
for i in range(3):
per += self.__vertices[i].distance_from_point(self.__vertices[(i + 1) % 3])
return per
triangle = Triangle(Point(0, 0), Point(1, 0), Point(0, 1))
print(triangle.perimeter())