import math class Point: '''Represents an (x, y) coordinate pair.''' def __init__(self, new_x, new_y): '''Set up a new Point object with an x and y value.''' self.x = new_x self.y = new_y def distance_to(self, other_point): '''Return the distance from this point to other_point.''' x1 = self.x y1 = self.y x2 = other_point.x y2 = other_point.y return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) def distance_origin(self): '''Return the distance from this point (aka self) to the origin.''' origin = Point(0, 0) return self.distance_to(origin) def __str__(self): '''Return a string representation of the point object.''' return '({0}, {1})'.format(self.x, self.y) def main(): '''Test the Point class.''' p1 = Point(3, 7) p2 = Point(-10, 1) print("p1 is " + str(p1)) print("p2 is " + str(p2)) dist = p1.distance_to(p2) print("distance is " + str(dist)) main()