Write a function distance that calculates the distance between two points (x1, y1) and (x2, y2). All numbers and return values should be of floating type. Use this function in your program. The values of the points shall be provided by the end user.
import math
def distance(x1, y1, x2, y2):
return (math.sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)))
x1 = float(input('Enter X1: '))
y1 = float(input('Enter Y2: '))
x2 = float(input('Enter X2: '))
y2 = float(input('Enter Y2: '))
print('The distance is', '{:.2f}'.format(distance(x1, y1, x2, y2)))
Comments
Leave a comment