import math
# fill in this function to return the distance between the two points!
first_point = (1, 1)
second_point = (4, 5)
def distance(first_point, second_point):
x1= first_point[0]
x2= second_point[0]
y1= first_point[1]
y2= second_point[1]
power1 = pow(y2 - y1, 2)
power2 = pow(x2 - x1, 2)
return math.sqrt (power1 + power2)
print (distance(first_point, second_point))
7.1.10: Coordinate Pairs
Share
Your function for calculating the distance between two points is almost correct, but the indentation for the code inside the function needs to be fixed. Here’s the corrected version:
import math
first_point = (1, 1)
second_point = (4, 5)
def distance(first_point, second_point):
x1 = first_point[0]
x2 = second_point[0]
y1 = first_point[1]
y2 = second_point[1]
power1 = pow(y2 - y1, 2)
power2 = pow(x2 - x1, 2)
return math.sqrt(power1 + power2)
print(distance(first_point, second_point))
### Explanation:
1. Indentation: Make sure that all lines inside the function `distance` are indented properly; otherwise, it will raise an error.
2. Distance Formula: The function calculates the Euclidean distance between two points (x1, y1) and (x2, y2) using the formula: ( text{distance} = sqrt{(x2 – x1)^2 + (y2 – y1)^2} ).
When you run this code, it should correctly output the distance between the two points, which is 5.0. If you need further assistance or have more questions, feel free to ask!