These questions follow Loops. A loop is a bargain with the computer: you describe one round precisely, it does all of them.

Questions

  1. Which of these needs a loop — (a) locking one door, (b) handing back 28 quizzes, (c) wearing boots if it rains?
  2. Predict the output — how many lines, and what is on each?
    for number in range(4):
        print(number)
  3. Trace total through every round, then predict what prints.
    total = 0
    for number in range(1, 4):
        total = total + number
    print(total)
  4. Find the bug. This countdown never reaches lift-off — or ends.
    count = 3
    while count > 0:
        print("T-minus", count)
  5. Write a loop that prints 10 down to 1 — countdown style.
  6. Challenge. Keep asking Password? until the user types sesame, then print how many attempts were needed.

Answers

Curriculum connection

C2.4

write programs that include sequential, selection, and repeating events

Link to original

C1.5

identify and explain situations in which conditional and repeating structures are required

Link to original