Module 4 · Manhattan Navigation
Lesson 4-2 · The Planner: A Path That Grows — Knowledge ChecksAnswer key
What does this print?
stops = [] stops.append((0, 1)) stops.append((0, 2)) stops.append((1, 2)) print(len(stops), stops)
append() adds to the end, so the items stay in the order they were added. Three appends, three tuples, so len() is 3.
A loop is meant to build a path, but the list ends up holding only the last position. What's wrong?
If append() isn't indented inside the loop, it runs a single time after the loop ends and records just the final position.
Why is the path for Leg 2, (2, 3) to (1, 0), empty?
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.
Which is true?
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.