Answer to Question #187851 in Python for Ali

Question #187851

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-04T07:12:39-0400
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]))

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