# File: ChapterGraphics/distance.py """ distance(P1,P2) computes the distance between two points in 2D distance P1(-1,2) and P2(3,5) is 5.0 """ from math import sqrt from graphics import * def distance(P1,P2): x1, y1 = P1.getX(), P1.getY() x2, y2 = P2.getX(), P2.getY() return sqrt((x2 - x1)**2 + (y2 - y1)**2) def main(): p1 = Point(-1, 2) p2 = Point(3, 5) d = distance(p1,p2) print("distance P1(-1,2) and P2(3,5) is ", d) main()