Classes and Objects
2 / 4
Custom methods
Add the following two methods the the class Point
:
- A method
translate
with two parametersdx
anddy
. The method should move the point with these distances. - A method
distance
with one parameterp
which should be another point. The method should return the distance between the pointself
andp
.
Hint: the distance between point $(x_1,y_1)$ and point $(x_2,y_2)$ is $\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}$.
Use the function math.sqrt
to compute the square root.
Use x**2
to square a variable x
.