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 | |
|---|---|---|
| 1count += 1 | Acount = 0 for i in range(5): count += 1 | |
| 2total += score | B=+ is written instead of +=, so total is just set to n each time instead of adding to it. It should be total += n. | |
| 3Set a counter to 0 before the loop so it starts with nothing counted | CAdds the value of score onto total, building a running total inside the loop | |
| 4Add each number from a list to a running total inside a for loop | Dtotal = 0 for n in marks: total += n | |
| 5for i in range(5): count = 0 count += 1 | Ecount is set to 0 inside the loop, so it resets every repeat and always ends up as 1. It should be set to 0 before the loop. | |
| 6total = 0 for n in marks: total =+ n | FAdds 1 to the variable count each time it runs, so it counts how many times the loop repeats |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
count += 1 — Set count = 0 before a loop, then use count += 1 inside it to add 1 each repeat. Use total += value to build a running total.count = 0
for i in range(5):
count += 1total = 0
for n in range(1, 4):
total += nscore = 0
for n in [4, 7, 9]:
score += ncount = 0
for name in ["Mia", "Leo"]:
count += 1total = 0
for p in [5, 10, 15]:
total += p