Question #187809

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.


Expert's answer

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)))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS