Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1while True: print("Hi") | AUpdates the loop variable each time round so the while condition can eventually become False | |
| 2count = count + 1 | Bwhile count < 3: count = count + 1 | |
| 3Adding break inside the loop is one way to exit a loop that would otherwise run forever | Cwhile True: if count == 5: break | |
| 4A loop with an updated variable ends because its condition finally becomes False | DA condition that can never be False, so this loop runs forever unless you use break or press Stop | |
| 5count = 0 while count < 5: print(count) | Ecount never changes inside the loop, so count < 5 stays True forever. Add count = count + 1 inside the loop. | |
| 6count = 10 while count > 0: count = count + 1 | Fcount moves away from 0, so count > 0 can never become False. Change it to count = count - 1. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
infinite loop — A while loop whose condition never becomes False, often because the loop variable is never updated. Stop it with the Stop button, or fix it by changing the variable inside the loop.count = 0
while count < 3:
count = count + 1while True:
if input("Quit? ") == "y":
breakwhile True:
print("Hello")count = 10
while count > 0:
count = count - 1count = 0
while count < 3:
count = count + 1