← QCE Digital Solutions Unit 4

Desk checking an algorithm that calls a function

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.

Understanding Desk checking an algorithm that calls a function in QCE Digital Solutions Unit 4

What it does: The argument 50 in the caller is copied into the parameter price, so the function trace table starts with price = 50. The variable a is local to area(). The caller's table only receives the returned value, not the column a. Every call has its own arguments and may return a different value. Record each call separately.

Common mistakes: The function prints the value instead of returning it, so there is no returned value to carry back into the caller's trace table and total would be None. It should be 'return result'. c is not a parameter or a local variable, so it has no column in the function's trace table. The function should use its own parameters: 'return a + b'.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 127–333) and word search (Modules 127–401).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
When desk checking an algorithm that calls a function, what should you record first in the function's trace table?
The final output of the whole programThe argument values passed in, shown under the parameter columns
Matches
Caller table: x = 4, then result = n
↓
The 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.
Applying
Meanings
Term
desk check
Meaning
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.
Practice
define double(n)
Testing
Gaps
result ← (4)
Check Answer
Spots
2 result = n * 2
3 print(result)

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Snow Leopard' badge — Silent Debugger, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. When desk checking an algorithm that calls a function, what should you record first in the function's trace table?
A. The argument values passed in, shown under the parameter columns ✓
B. The final output of the whole program
Each call starts with its argument values copied into the parameter columns. You then follow the function's statements from there.
2. A function returns a value to its caller. What do you do with that value in the desk check?
A. Leave it in the function's table and ignore it
B. Carry it back and write it into the caller's trace table ✓
The returned value replaces the function call in the caller. It is stored or used in the caller's trace table, for example in the variable it is assigned to.
3. Which statement about variables in a desk check is correct?
A. A function's local variables share columns with the caller's variables
B. A function's local variables get their own columns, separate from the caller's variables ✓
Local variables and parameters exist only while the function runs. Keep them in the function's own trace table, apart from the caller's variables.
4. The caller runs total = add(4, 6) and add(a, b) returns a + b. What goes in the function's returned value row?
A. 10 ✓
B. total
The function returns the value 10. After the return, 10 is carried back and written under total in the caller's table.
5. The same function is called twice with different arguments. How should you desk check it?
A. Trace each call separately, using its own argument values ✓
B. Trace it once and reuse the same results for both calls
Every call has its own arguments and may return a different value. Record each call separately.

Match the Pairs

result ← double(5) → In the caller's trace table, record the argument 5 and then write the value returned by double() into the result column.
define double(n) return n * 2 → In the function's own trace table, the parameter column n receives the argument value, then the return row records n * 2.
The 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. → total ← addTax(50) define addTax(price)
A 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. → define area(w, h) a ← w * h return a
Caller table: x = 4, then result = n → The 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.
Function table: n = 3, a = 9, return row left blank → The returned value row was never filled in, so the caller has nothing to carry back into its trace table.

Key Term

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.

Fill in the Blanks

1. define double(n) return n * 2 result ← double(4)
Hint: Type the name of the function that the caller uses, matching the define line.
2. define add(a, b) return a + b sum ← add(3, 4)
Hint: Type the second parameter name, which takes the second argument value in the trace table.
3. define half(n) return n / 2 x ← half(10)
Hint: Type the keyword that sends a value back to the caller, shown in the returned value row.
4. x ← 4 result ← double(x) OUTPUT result
Hint: Type the caller variable whose current value is passed in as the argument.
5. define addTax(p) total ← p * 1.1 return total
Hint: Type the local variable that holds the value to return, which is then carried back to the caller.

Spot the Error

Question 1
A def double(n):
B result = n * 2
C print(result)
D total = double(5)
Line C — The function prints the value instead of returning it, so there is no returned value to carry back into the caller's trace table and total would be None. It should be 'return result'.
Question 2
A def add(a, b):
B return a + c
C x = 4
D y = add(x, 3)
Line B — c is not a parameter or a local variable, so it has no column in the function's trace table. The function should use its own parameters: 'return a + b'.
Question 3
A def area(w, h):
B return w * h
C size = area(3)
D print(size)
Line C — The function has two parameters (w and h), so the call needs two argument values. Desk checking would find h has no value. It should be 'size = area(3, 4)'.
Question 4
A def average(a, b):
B total = a + x
C return total / 2
D x = average(6, 10)
Line B — x is a caller variable that does not exist yet when the function runs. A function should only use its own parameters and local variables. It should be 'total = a + b'.
Question 5
A def square(n, m):
B return n * n
C answer = square(4)
D print(answer)
Line A — The call passes one argument (4) but the header now has two parameter columns, so m would never get a value. The header should be 'def square(n):'.

Student with a class code? Join your class →