Lab 6: Knowledge Check

These questions check your knowledge of concepts from this lab. Use the button at the bottom to show your answers once you've attempted them.

  1. True or false: If you store a list in a variable, and then modify that list using a method like .append or .insert, when you access the list using the variable again, the value will be changed.
    True False
  2. What does the .append method of lists return?
    1. Nothing: it just modifies the list you applied it to.
    2. The value that you appended to the list.
    3. The list that you appended to.
  3. Which of the following statements are true about for vs. while loops? (pick one or more)
    1. For loops are more general than while loops.
    2. While loops are more general than for loops.
    3. Both for and while loops create loop variables.
    4. Both for and while loops have continuation conditions.
    5. Unlike while loops, for loops always loop over a sequence.
    6. An index loop can be created using a while loop or a for loop.
  4. If we run the following code, what is the sequence of numbers that gets printed (ignoring formatting)?
    x = 0
    while x < 7:
        x += 2
        print(x)
        x += 2
        print(x)
        x += 2
    print(x)

    1. 2, 4, 6
    2. 2, 4, 6, 8
    3. 2, 4, 8
    4. 2, 4, 8, 10
    5. 2, 4, 8, 10, 12
    6. 2, 4, 8, 10, 14, 16, 18

Table of Contents