215k views
1 vote
Write a function to calculate the distance between two points Distance( x1, y1,x2.2) For example Distance(0.0,3.0, 4.0.0.0) should return 5.0 Use the function in main to loop through reading in pairs of points until the all zeros are entered printing distance with two decimal precision for each pair of points.

For example with input
32 32 54 12
52 56 8 30
44 94 4439 6
5 19 51 91 7.5
89 34 0000
Your output would be:__________.
a. 29.73
b. 51.11
c. 55.00
d. 73.35
e. 92.66

User Sge
by
5.4k points

1 Answer

5 votes

Answer:

The function in Python3 is as follows

def Distance(x1, y1, x2, y2):

dist = ((x1 - x2)**2 +(y1 - y2)**2)**0.5

return dist

Step-by-step explanation:

This defines the function

def Distance(x1, y1, x2, y2):

This calculates distance

dist = ((x1 - x2)**2 +(y1 - y2)**2)**0.5

This returns the calculated distance to the main method

return dist

The results of the inputs is:


32, 32, 54, 12 \to 29.73


52,56,8,30 \to 51.11


44,94,44,39\to 55.00


19,51,91,7.5 \to 84.12


89,34,00,00 \to 95.27

User Fabian Linzberger
by
6.1k points