I am doing an exercise in the textbook Think Python by Allen Downey. I am sure that the code is correct but it keeps showing the same problem:
Traceback (most recent call last):
File "C:/Users/ADMIN/PycharmProjects/ProgrammingFundamental101/EXTRA EFFORTS/Classes_and_Objects.py", line 80, in <module>
print(distance_between_points(blank.x, blank.y))
File "C:/Users/ADMIN/PycharmProjects/ProgrammingFundamental101/EXTRA EFFORTS/Classes_and_Objects.py", line 74, in distance_between_points
dx = p1.x - p2.x
AttributeError: 'float' object has no attribute 'x'
The code is below:
def distance_between_points(p1, p2):
dx = p1.x - p2.x
dy = p1.y - p2.y
dist = math.sqrt(dx**2 + dy**2)
return dist
print(distance_between_points(blank.x, blank.y))
Both points blank.x and blank.y have been defined and assigned with values of 3 and 4.
What is going wrong with the arguments or the parameter?