Question: Calculate the Euclidean distance between two points using the distance formula: d = ( x 2 x 1 ) 2 + ( y 2 y

Calculate the Euclidean distance between two points using the distance formula:
d=(x2x1)2+(y2y1)2
Function Requirements
get_float_input(prompt)
Validates user input to ensure it can be converted to a float. Returns the float value.Catches ValueError if the input is not a valid float, and continues to prompt the user for input. It does not exit the function until valid input is received.
get_int_input(prompt)
Validates user input to ensure it can be converted to an integer. Returns the integer value.Catches ValueError if the input is not a valid integer, and continues to prompt the user for input. It does not exit the function until valid input is received.
calculate_distance(x1, y1, x2, y2)
Calculates the distance between two points using the distance formulaReturns the calculated distanceYou may use the ** operator to calculate the square of a numberYou may use the math.sqrt function to calculate the square root
print_formatted_result(distance, precision)
Formats the distance result with specified precisionPrints the formatted result to the console
Example Runs
Test Case 1: Basic horizontal line
Enter x1 coordinate: 0 Enter y1 coordinate: 0 Enter x2 coordinate: 3 Enter y2 coordinate: 0 Enter the precision: 2 Distance =3.00
Test Case 2: 3-4-5 triangle
Enter x1 coordinate: 0 Enter y1 coordinate: 0 Enter x2 coordinate: 3 Enter y2 coordinate: 4 Enter the precision: 2 Distance =5.00
Test Case 3: Invalid coordinate input
Enter x1 coordinate: abc Invalid input: Coordinate must be a number. Enter x1 coordinate: 0 Enter y1 coordinate: 1.2.3 Invalid input: Coordinate must be a number. Enter y1 coordinate: 0 Enter x2 coordinate: 3 Enter y2 coordinate: 4 Enter the precision: 2 Distance =5.00
Test Case 4: Invalid precision input
Enter x1 coordinate: 0 Enter y1 coordinate: 0 Enter x2 coordinate: 3 Enter y2 coordinate: 4 Enter the precision: abc Invalid input: Must be an integer. Enter the precision: 1.5 Invalid input: Must be an integer. Enter the precision: 2 Distance =5.00
Test Case 5: Negative coordinates
Enter x1 coordinate: -2 Enter y1 coordinate: -1 Enter x2 coordinate: 2 Enter y2 coordinate: 2 Enter the precision: 1 Distance =5.0
Test Case 6: High precision
Enter x1 coordinate: 1.1 Enter y1 coordinate: 2.1 Enter x2 coordinate: 1.2 Enter y2 coordinate: 2.3 Enter the precision: 5 Distance =0.22361

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!