Lesson 5 · Implementing the Manhattan Class — Knowledge ChecksAnswer key
What's the main advantage of the Manhattan class over the standalone function?
The object remembers its position. You pass the start once when you create it, then just ask for paths to different destinations.
After nav = Manhattan((2, 1)), what does nav.position hold?
__init__ runs at creation and stores whatever you passed as self.position — here, the tuple (2, 1).
In the class version, where does the old start parameter's information come from now?
__init__ saved the start as self.position. The method reads it there, so you never pass the start to compute_path — only the destination.
You create nav = Manhattan((0, 0)) and call nav.compute_path((2, 3)). Afterward, what is nav.position?
compute_path uses local variables for the walk, so the stored self.position is untouched. That's what lets you plan several routes from the same start.