Skip to main content
Module 5 · Pathfinding Around Obstacles

Lesson 5-4 · The Pathfinding Functions — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. Why must a planner be TOLD the robot's position instead of remembering it?

    1. A.So the planner and the driving code can never disagree about where the robot is✓
    2. B.Because functions cannot store values between calls
    3. C.To make the path shorter
    4. D.Because the position changes while the path is being computed

    The driving code owns the position. Two copies of the same fact is how a planner ends up planning from an intersection the robot left three steps ago.

  2. Why does add_blocked() not need `global BLOCKED`, when set_threshold() in Lesson 2-7 needed `global THRESHOLD`?

    1. A.append changes the list in place; set_threshold reassigns the name✓
    2. B.Lists are always global
    3. C.BLOCKED is in capital letters
    4. D.It does need it — the code above is wrong

    `global` is needed only to reassign a module-level name. Appending to a list changes the list that BLOCKED already names; the name itself is untouched.

  3. (1,1) is blocked. Someone wrote build_graph with the first `in blocked` check but forgot the second. What is wrong with the result?

    1. A.(1,1) is not a key, but it still appears in its neighbors’ lists — there are edges into the wall✓
    2. B.(1,1) is a key with an empty neighbor list
    3. C.Nothing — the first check is enough
    4. D.The graph has 16 keys instead of 15

    The first check removes (1,1) as a key. Only the second check removes it from the lists of (0,1), (1,0), (1,2) and (2,1). Without it, a search could step into the wall.