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 | |
|---|---|---|
| 1result = [] | Afor mark in marks: if mark >= 50: passes.append(mark) | |
| 2result.append(mark) | BThe return is indented inside the loop, so the function exits after the first item and returns a list with at most one item. | |
| 3Filtering: only keep items that pass a test by appending them inside an if statement | CCreates an empty list at the start of the function to collect the answers | |
| 4Return the finished list after the loop ends, at the same indent level as the for loop | Dfor n in nums: result.append(n * 2) return result | |
| 5def get_evens(nums): result = [] for n in nums: if n % 2 == 0: result.append(n) return result | EAdds the current item to the end of the list being built inside the loop | |
| 6def get_big(nums): for n in nums: result = [] if n > 10: result.append(n) return result | FThe empty list is created inside the loop, so it resets every time and the earlier items are lost. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
result = [] — Start a function with an empty list, append each wanted item inside a loop, then return the finished list after the loop ends. Filtering builds a new list.def keep(marks):
result = []
for m in marks:for n in numbers:
if n > 50:
result.append(n) for n in numbers:
result.append(n)
return result for w in words:
result.append(w)
return result for mark in marks:
if mark >= 50:
result.append(mark)