Skip to main content
Module 4 · Manhattan Navigation

Lesson 5 · Implementing the Manhattan Class — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. What's the main advantage of the Manhattan class over the standalone function?

    1. A.It runs faster
    2. B.It stores the start position once, so you don't repeat it on every call
    3. C.It uses fewer while loops
    4. D.It doesn't need a destination

    The object remembers its position. You pass the start once when you create it, then just ask for paths to different destinations.

  2. After nav = Manhattan((2, 1)), what does nav.position hold?

    1. A.An empty tuple
    2. B.(2, 1)
    3. C.2
    4. D.Nothing until compute_path is called

    __init__ runs at creation and stores whatever you passed as self.position — here, the tuple (2, 1).

  3. In the class version, where does the old start parameter's information come from now?

    1. A.It's passed to compute_path each time
    2. B.From self.position, stored back in __init__ when the object was created
    3. C.It defaults to (0, 0)
    4. D.From a global variable

    __init__ saved the start as self.position. The method reads it there, so you never pass the start to compute_path — only the destination.

  4. You create nav = Manhattan((0, 0)) and call nav.compute_path((2, 3)). Afterward, what is nav.position?

    1. A.(2, 3) — it moved to the destination
    2. B.(0, 0) — compute_path only reads self.position, it never changes it
    3. C.The full path list
    4. D.Undefined

    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.