How to calculate the Euclidean distance between two points in Python

1 Answer

0 votes
import math

# The Euclidean distance is a measure of the straight-line distance 
# between two points in a 2D or 3D space

def CalculateEuclideanDistance(x1, y1, x2, y2):
    # Calculate Euclidean distance between two 2D points.
    return math.sqrt((x2 - x1)**2 + (y2 - y1)**2)

x1, y1 = 3.0, 4.0
x2, y2 = 5.0, 9.0

distance = CalculateEuclideanDistance(x1, y1, x2, y2)
print(f"Euclidean Distance: {distance:.5f}")



'''
run:

Euclidean Distance: 5.38516

'''

 



answered Oct 12 by avibootz
edited Oct 13 by avibootz
...