diff --git a/lab41.py b/lab41.py new file mode 100644 index 0000000..a035a6a --- /dev/null +++ b/lab41.py @@ -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))