Skip to main content
Module 4 · Manhattan Navigation

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

Name Date
  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

    Answer Why?

  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

    Answer Why?

  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)

    Answer Why?

  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

    Answer Why?

  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

    Answer Why?