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 | |
|---|---|---|
| 1total = sum(marks) | Amid = (low + high) // 2 | |
| 2def show(x): print(x * 2) | Blen(names) is recalculated on every pass of the loop instead of being stored once in a variable | |
| 3Choosing a better algorithm: binary search on a sorted list is faster than checking every item | CUses a built-in function to add up a list, replacing a longer hand-written loop | |
| 4Readability vs speed: a clear variable name makes code easier to maintain even if it is not faster | Daverage_mark = total / count | |
| 5for i in range(len(names)): print(len(names)) | EMoves repeated code into one function that can be called many times | |
| 6print(a * 2) print(b * 2) print(c * 2) | FThe same calculation is copied three times instead of using a loop or function to remove the repeated code |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
optimisation — Changing code so it runs faster, uses less memory or is easier to read, without changing what it does. For example, removing repeated code or using a built-in function.total = sum(marks)for i in range(5):
print("Hello")mid = (low + high) // 2ordered = sorted(scores)limit = len(items)
while i < limit: