Why does `distance` hand back a number while `to_origin` returns nothing at all — and what does each one do to `self`?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
The Point class below already has __init__ and distance. Add a method named to_origin that takes only self and always leaves the point sitting at (0, 0), wherever it happened to be before. It hands nothing back — its whole job is to overwrite the object's own data.
Then call it on point, which starts at (3, 4), and assign to after the tuple (point.x, point.y).
The distance method
Write the body from Pythagoras, squaring self.x - other.x and self.y - other.y, adding the squares and raising the sum to 0.5, with other a second Coordinate.
to_origin as a method that changes the object
Write the two-line body setting self.x and self.y to 0, and record that the call hands back None while the object's own data attributes end up changed.
A hand-trace of the driver code
Trace c = Coordinate(3, 4) and origin = Coordinate(0, 0) through c.distance(origin) printing 5.0, then c.to_origin() leaving c.x and c.y both at 0.
How to read dot notation
State that the name before the dot is an object and the name after it a data attribute or method of that type, callable only if it was defined in the class.