aggiunge esercizio 42
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import math
|
||||
|
||||
class Point:
|
||||
|
||||
def __init__(self, x, y):
|
||||
self.__x = float(x)
|
||||
self.__y = float(y)
|
||||
|
||||
def getx(self):
|
||||
return self.__x
|
||||
|
||||
def gety(self):
|
||||
return self.__y
|
||||
|
||||
def distance_from_xy(self, x, y):
|
||||
return math.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.__vertici = [vertice1, vertice2, vertice3]
|
||||
|
||||
def perimeter(self):
|
||||
v = self.__vertici
|
||||
lato1 = v[0].distance_from_point(v[1])
|
||||
lato2 = v[1].distance_from_point(v[2])
|
||||
lato3 = v[2].distance_from_point(v[0])
|
||||
return lato1 + lato2 + lato3
|
||||
|
||||
triangle = Triangle(Point(0, 0), Point(1, 0), Point(0, 1))
|
||||
print(triangle.perimeter())
|
||||
Reference in New Issue
Block a user