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 | |
|---|---|---|
| 1def total_of(scores): | ADefines a function with a parameter called scores that will receive a list | |
| 2total_of([5, 8, 9]) | BCalls the function and passes in a list of three numbers | |
| 3The function can loop over every item in the list it was given | CThe call uses a list variable that has not been created, so Python raises a NameError. | |
| 4The same function can be reused with different lists | Dfor s in scores: total += s | |
| 5def total_of([5, 8, 9]): | EA list value was put in the def line. The header needs a parameter name like scores, and the list is passed when calling the function. | |
| 6total_of(scores) # scores was never created | Ftotal_of(maths) total_of(science) |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
def total_of(scores): — A function header with a list parameter. Pass a list when you call it, like total_of([5, 8, 9]), and the function can loop over or read its items.def total(scores):
result = 0
for s in scores:def total(scores):
return sum(scores)def total(scores):
result = 0
for score in scores:marks = [70, 85, 90]
print(total(marks))def average(scores):
return sum(scores) / len(scores)