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 show_menu(): print("1. Play") | Ashow_menu() | |
| 2def add(a, b): return a + b | BA function: it sends a value back to the code that called it so the result can be stored or used | |
| 3A function's returned value can be stored in a variable for later use | CA procedure: it carries out a task (printing) but does not return a value to the caller | |
| 4A procedure is called as its own statement because it has no result to store | Darea only prints and has no return, so it is a procedure. size stores None, not 12. Use return w * h to make it a function. | |
| 5def area(w, h): print(w * h) size = area(3, 4) | Etotal = add(2, 3) | |
| 6def greet(name): return "Hi " + name greet("Sam") | Fgreet returns a value but the result is never printed or stored, so nothing is shown. Use print(greet("Sam")) or store it in a variable. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
procedure vs function — A procedure carries out a task without returning a value, while a function returns a value to the code that called it, so the result can be stored or used.def showTotal(a, b):
print(a + b)def add(a, b):
return a + bdef add(a, b):
return a + b
total = add(2, 3)def showMenu():
print("1. Play")
print("2. Quit")def showArea(w, h):
print(w * h)
showArea(3, 4)