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 add(a, b): print(a + b) total = add(2, 3) | Aarea() prints instead of returning, so it gives back None and None + 10 causes a TypeError. Replace print with return. | |
| 2def add(a, b): return a + b total = add(2, 3) | Bdef total(nums): s = 0 for n in nums: s += n return s | |
| 3A return placed inside the loop ends the function on the first pass, so only the first item is handled | Cdef make_total(a, b): result = a + b return result | |
| 4A local variable only exists inside its function, so the caller must receive its value with return | Dtotal becomes 5, because return sends the sum back to the caller | |
| 5def area(w, h): print(w * h) big = area(4, 5) + 10 | Eresult is a local variable, so it cannot be used outside the function and causes a NameError. Return it and store the answer from the call. | |
| 6def make_total(a, b): result = a + b make_total(2, 3) print(result) | Ftotal becomes None, because add() prints the sum but never returns it |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
return — Sends a value back to the caller. If a function only prints and has no return, it gives back None, so the caller cannot use the result.def add(a, b):
return a + bdef show(n):
print(n)
print(show(3) == None)def first(nums):
for n in nums:
return ndef divide(a, b):
return a / b
print(divide(10, 2))def area(w, h):
return w * h
print(area(3, 4))