aggiunge esercizio 41
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
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())
|
||||||
|
|
||||||
|
|
||||||
|
# --- TEST ---
|
||||||
|
point1 = Point(0, 0)
|
||||||
|
point2 = Point(1, 1)
|
||||||
|
|
||||||
|
print(point1.distance_from_point(point2))
|
||||||
|
|
||||||
|
print(point2.distance_from_xy(2, 0))
|
||||||
Reference in New Issue
Block a user