Python Program to Calculate Distance Between Two Points ( Co-ordinates)
This python program calculates distance between two points or coordinates given by user using distance formula.
This program uses following formula for distance between two points:
Distance Formula = ( (x2 - x1)2 + (y2 - y1)2 )½
Where: (x1, y1) = coordinates of the first point & (x2, y2) = coordinates of the second point
Python Source Code: Distance Calculator
# Python Program to Calculate Distance
# Reading co-ordinates
x1 = float(input('Enter x1: '))
y1 = float(input('Enter y1: '))
x2 = float(input('Enter x2: '))
y2 = float(input('Enter y2: '))
# Calculating distance
d = ( (x2-x1)**2 + (y2-y1)**2 ) ** 0.5
# Displaying result
print('Distance = %f' %(d))
Python Distance Calculator Output
Enter x1: 4 Enter y1: 8 Enter x2: 5 Enter y2: 1 Distance = 7.071068