Files
corso-python/lab41.py
T

29 lines
544 B
Python
Raw Normal View History

2026-04-13 15:56:49 +02:00
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))