#pointsDistance.py #randomly generate pairs of (x,y) integer points in the plane, #calculate the distance between them. summing the distances import random import math def distance_pair_points(x1,y1, x2,y2): return math.sqrt((x2-x1)**2+(y2-y1)**2) range_nums = int(input("Enter the range of the points, +/-? ")) num_points = int(input("Enter the number of pairs of random points: ")) sum_dist = 0 max_distance = float('-inf') #smallest possible number for p in range(num_points): x1 = random.randint(-range_nums,range_nums) y1 = random.randint(-range_nums,range_nums) x2 = random.randint(-range_nums,range_nums) y2 = random.randint(-range_nums,range_nums) dist = distance_pair_points(x1,y1, x2,y2) sum_dist += dist print(f"({x1},{y1})<---->({x2},{y2}) is {dist}") if dist > max_distance: max_distance = dist print("Sum of distances:",sum_dist," Largest distance:",max_distance,\ " Average distance:",sum_dist/num_points)