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): return a + b | Aage is stored as None because get_age() prints 13 but does not return it. Use return 13 instead. | |
| 2def add(a, b): print(a + b) | Btotal = add(2, 3) | |
| 3Storing the result of a function that returns a value in a variable | COnly shows the sum on screen, and the function gives back None | |
| 4Using a returned result inside a calculation | Dsquare() only prints and gives back None, so adding 1 to None causes a TypeError. Use return n * n instead of print(n * n). | |
| 5def square(n): print(n * n) answer = square(4) + 1 | Edouble = add(2, 3) * 2 | |
| 6def get_age(): print(13) age = get_age() | FHands the sum back to the caller so it can be stored or used in a calculation |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
return — Hands a value back to the caller so it can be stored in a variable or used in a calculation. print() inside a function only shows the value on screen, and the function then gives back None.def total(a, b):
return a + b
print(total(2, 3))def hi():
print("Hi")
print(hi() == None)def cube(n):
return n ** 3
volume = cube(3)def double(n):
return n * 2
print(double(4) + 1)def greet():
print("Hello!")
greet()