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 ← double(5) | Atotal ← addTax(50) define addTax(price) | |
| 2define double(n) return n * 2 | BThe caller's table uses the parameter name n instead of the returned value. n is local to the function and does not exist in the caller. | |
| 3The argument column in the caller must match the parameter column in the function: the argument value is copied into the parameter when the call starts. | CIn the caller's trace table, record the argument 5 and then write the value returned by double() into the result column. | |
| 4A variable created inside the function is local, so it gets a column in the function's trace table only, not in the caller's table. Only the returned value goes back to the caller. | Ddefine area(w, h) a ← w * h return a | |
| 5Caller table: x = 4, then result = n | EIn the function's own trace table, the parameter column n receives the argument value, then the return row records n * 2. | |
| 6Function table: n = 3, a = 9, return row left blank | FThe returned value row was never filled in, so the caller has nothing to carry back into its trace table. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
desk check — Trace by hand: record each function call's argument values, follow its statements to the return, then carry the returned value back into the caller's trace table.define double(n)
return n * 2
result ← double(4)define add(a, b)
return a + b
sum ← add(3, 4)define half(n)
return n / 2
x ← half(10)x ← 4
result ← double(x)
OUTPUT resultdefine addTax(p)
total ← p * 1.1
return total