Skip to main content
Module 4 · Manhattan Navigation

Lesson 4-7 · Tuples and Lists: What You Now Know — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. A program must remember every intersection where the robot found an obstacle, adding to it as the robot drives. What should it use?

    1. A.One tuple, with append()
    2. B.A list of tuples: each obstacle is an (x, y) tuple, and the list grows✓
    3. C.A tuple of lists
    4. D.Two separate variables, x and y

    Each position is a fixed pair, so a tuple. The collection grows as the robot drives, so a list. That is exactly what Module 5 does.

  2. After these lines, what is total?

    legs = [(2, 3), (1, 0)]
    total = 0
    for leg in legs:
        x, y = leg
        total = total + x + y
    1. A.2
    2. B.6✓
    3. C.4
    4. D.An error: a tuple cannot be unpacked inside a loop

    First pass: x is 2, y is 3, total becomes 5. Second pass: x is 1, y is 0, total becomes 6.

  3. Given path = [(1, 0), (2, 0), (3, 0)], which line gives the y of the last position?

    1. A.path[3][1]
    2. B.path[2][1]✓
    3. C.path[1][2]
    4. D.path(2, 1)

    Three items have indexes 0, 1 and 2, so the last is path[2]. Its y is index 1. path[3] would be an IndexError.

  4. What does scores hold after these three lines?

    scores = [10, 20]
    backup = scores
    backup.append(30)
    1. A.[10, 20] -- backup is a separate copy
    2. B.[10, 20, 30] -- both variables refer to the same list✓
    3. C.[30]
    4. D.An error: you cannot assign a list to another name

    backup = scores stores the address that was in scores, not a copy of the list, so both variables lead to one list. Appending through either variable changes what both see.

  5. A function is handed a list called blocked and runs blocked.append((2, 2)). After it returns, what does the caller's list hold?

    1. A.What it held before: functions cannot change the caller's variables
    2. B.The old items plus (2, 2): the function and the caller refer to the same list✓
    3. C.Only (2, 2)
    4. D.Nothing: the list is emptied when the function ends

    The parameter holds the list's address, so append() changes the one list both sides share. Only assigning with = inside the function would leave the caller's list alone.