Skip to main content

Practice · 2 of 3

Slotted points

CHALLENGE
Difficulty: advanced+25 XP

Implement class Point with __slots__ = ('x', 'y'): - constructor takes x, y - instances must NOT support arbitrary attributes (p.z = 1 raises AttributeError) - __eq__/__hash__ consistent: equal points share a hash (define both) - distance_to(other) returns the Euclidean distance (use math.hypot)

Back to lesson: Practice: Custom Container Practice