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 | |
|---|---|---|
| 1for n in range(1, 6): if n > 3: print(n) | AThe if is not indented, so it is outside the loop. It runs only once after the loop ends, and only checks the last value of n. | |
| 2while lives > 0: if hit: lives = lives - 1 | Bfor n in range(1, 11): if n % 2 == 0: count = count + 1 | |
| 3Count only the even numbers by testing each number in a for loop | CThe if is not indented under the for line, so Python does not see it as part of the loop block, which causes an error. | |
| 4Keep asking in a while loop and make a decision each time the user answers | Dwhile guess != 7: guess = int(input()) if guess < 7: print("Too low") | |
| 5for n in range(1, 6): print(n) if n == 3: print("Three!") | EThe if is checked on every pass of the for loop, so only the numbers bigger than 3 are printed. | |
| 6for score in scores: if score > 50: print("Pass") | FThe if is checked every time the while loop repeats, and lives only goes down on passes where hit is True. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
if inside a loop — An if indented inside a loop's block is checked again on every repetition, so each pass can make a different decision.for n in range(1, 6):
if n > 3:
print(n)for score in [4, 9, 7]:
if score > 5:
print("Pass")for n in range(1, 11):
if n % 2 == 0:
print(n)n = 1
while n <= 5:
if n == 3:
print("Three!")
n = n + 1for age in [8, 12, 14]:
if age >= 12:
print("Teen")