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(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2)))
print('Enter coordinates X1,Y1, X2,Y2 (four floats separated by space):', end=' ')
coords = list(map(float, input().split()))
print('Distance is', distance(coords[0], coords[1], coords[2], coords[3]))
Comments
Leave a comment