If `point.distance(self.center)` and `self.center.distance(point)` give the same answer, which object is really running the method?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Read this class and the two objects made from it — you do not need to retype any of it.
class Reservoir(object): def __init__(self, litres): self.litres = litres def surplus_over(self, other): return self.litres - other.litres big = Reservoir(30) small = Reservoir(12)
Work out what the call small.surplus_over(big) evaluates to, and assign that number to surplus.
The is_inside1 and is_inside2 equivalence puzzle
Write both one-line bodies, label the type of point, self and self.center in each, and record the verdict that the two versions are functionally equivalent.
Designing the SimpleFraction type from its data
Record the decision that a fraction is a pair of integers, write the __init__ setting self.num and self.denom, and list adding, multiplying, dividing and inverting as its behaviors.
How actual parameters map onto self and other
Write the times and plus bodies, then trace f1 = SimpleFraction(3, 4) and f2 = SimpleFraction(1, 4) through f1.plus(f2) giving 1.0 and f1.times(f2) giving 0.1875.