import math def distance(point1, point2): ''' return the distance between two points ''' # sqrt (change in x square + change in y square) point1x = point1[0] point1y = point1[1] point2x = point2[0] point2y = point2[1] change_in_x = point1x - point2x change_in_y = point1y - point2y return math.sqrt(change_in_x**2 + change_in_y**2) def comparePointToPoints(point, points): ''' print out the distance between point and all the points ''' # for all points for other_point in points: # compute distance between point and each point d = distance(point, other_point) print("distance between", point, " and ", other_point, "is", d) def main(): points = [ [1,1], [2,3], [2,-3], [-1,-1], [-2,1] ] ''' for i in range(-1,len(points)-1): #d = distance(points[i], points[(i+1)%len(points)]) d = distance(points[i], points[i+1]) print("distance between", points[i], " and ", points[i+1], "is", d) ''' # for each point for point in points: # compare it to every other point comparePointToPoints(point, points) for point in points: for other_point in points: # compute distance between point and each point d = distance(point, other_point) print("distance between", point, " and ", other_point, "is", d) # run the program main()