Skip to main content
Module 4 · Manhattan Navigation

Lesson 4-2 · The Planner: A Path That Grows — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. What does this print?

    stops = []
    stops.append((0, 1))
    stops.append((0, 2))
    stops.append((1, 2))
    print(len(stops), stops)
    1. A.3 [(1, 2), (0, 2), (0, 1)]
    2. B.3 [(0, 1), (0, 2), (1, 2)]✓
    3. C.6 [0, 1, 0, 2, 1, 2]
    4. D.1 [(1, 2)]

    append() adds to the end, so the items stay in the order they were added. Three appends, three tuples, so len() is 3.

  2. A loop is meant to build a path, but the list ends up holding only the last position. What's wrong?

    1. A.append() is broken
    2. B.The append() line is outside the loop, so it runs only once✓
    3. C.The path should have been a tuple
    4. D.The loop ran too many times

    If append() isn't indented inside the loop, it runs a single time after the loop ends and records just the final position.

  3. Why is the path for Leg 2, (2, 3) to (1, 0), empty?

    1. A.append() only works once per program
    2. B.Both while conditions are False from the start (2 is not < 1, 3 is not < 0), so neither loop runs✓
    3. C.The start and destination are the same
    4. D.The driver is still a stub

    East and north only handle x and y getting bigger. A while loop whose condition starts False does nothing. Going left or down needs two more loops: Lesson 4-3.

  4. Which is true?

    1. A.A tuple can grow with append(); a list cannot
    2. B.A list can grow and change; a tuple stays as it was made✓
    3. C.Lists and tuples are the same thing with different brackets
    4. D.A list can only hold numbers

    Lists use square brackets and can change, which suits a path that is built step by step. Tuples use parentheses and can't change, which suits a position.