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 i in range(len(arr)): | ALoops i through every index of arr, from 0 to the last position | |
| 2arr[i] = arr[i] * 2 | Brange() needs a number, but arr is a list. It should be range(len(arr)) so i covers every index. | |
| 3Totalling array elements: start a total at 0, then add arr[i] on every pass | Clargest = arr[0] for i in range(len(arr)): if arr[i] > largest: largest = arr[i] | |
| 4Finding the largest element: start with the first element and replace it whenever arr[i] is bigger | DAdds the index i instead of the element arr[i], so the total is of positions, not values. It should be total = total + arr[i]. | |
| 5for i in range(len(arr)): total = total + i | Etotal = 0 for i in range(len(arr)): total = total + arr[i] | |
| 6for i in range(arr): arr[i] = arr[i] + 1 | FChanges the element at position i in place by doubling it |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
for i in range(len(arr)): — Loops i through every index of arr, so arr[i] can be read or changed and you know each element's position. Used for totals, finding the largest value and editing in place.for i in range(len(arr)):total = 0
for i in range(len(arr)):
total = total + arr[i]largest = arr[0]
for i in range(len(arr)):
if arr[i] > largest: largest = arr[i]for i in range(len(arr)):
arr[i] = arr[i] * 2total = 0
for i in range(len(arr)):
total += arr[i]