DISTANCE BETWEEN TWO POINT

distance between two points python code
       
        
import math


def calculate_distance(x1, y1, x2, y2):
    distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
    return distance

# Example usage:
x1 = 1
y1 = 2
x2 = 4
y2 = 6

distance = calculate_distance(x1, y1, x2, y2)
print("The distance between the two points is:", distance)

OUTPUT:
             The distance between the two points is: 5.0
        
    

In this code, the calculate_distance() function takes the coordinates of two points (x1, y1) and (x2, y2) as input parameters. It uses the distance formula to calculate the distance and returns the result. The math.sqrt() function from the math module is used to calculate the square root of the expression (x2 - x1) ** 2 + (y2 - y1) ** 2. Finally, an example usage is provided, where the coordinates of the two points are assigned to variables x1, y1, x2, and y2. The calculated distance is then printed to the console.

Comments

Popular posts from this blog

ILLUSTRATIVE PROGRAMS IN PYTHON

Fibonacci Series

The Fibonacci series