Assignment: Write a program to find the distance between two points.
To find the distance (c) between two points (x1, y1) and (x2, y2) you use the equation:
where a and b are:
So, let’s find the distance between the points (1,7) and (5, 2) using python:
# define inputs x1 = 1 y1 = 7 x2 = 5 y2 = 2 # calculate distance a = x2 - x1 b = y2 - y1 c = (a**2 + b**2)**0.5 # output the result print("Distance between two points.") print("Point 1:", x1, y1) print("Point 2:", x2, y2) print("Distance:", c)
The result should look like:
Distance between two points. Point 1: 1 7 Point 2: 5 2 Distance: 6.40312