Answer to Question #187809 in Python for Ali

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.


1
Expert's answer
2021-05-01T14:10:09-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS