Coding worksheet · Coding
Trace the functions: what is returned? · Grade 9
Read 6 short Python programs about functions with parameters and return values and work out by hand what each one prints or the final value of a variable. Builds careful code tracing.
- Grade 9 · ages 14 to 15
- Medium
- 30 to 40 minutes
- 1 page
- Free
The answer key is a separate page for grown-ups. Sign in to download it.
The programs to trace
Directions: Trace each program line by line without a computer. Keep a note of every variable as it changes, then write exactly what the program prints or the final value.
- 1 What is printed?
- 1 def frame(word, edge):
- 2 return edge + word + edge
- 3 print(frame("pixel", "#"))
- 2 What is printed? Write each line.
- 1 def check(n):
- 2 if n % 3 == 0:
- 3 return "fits"
- 4 return "left over"
- 5 print(check(24))
- 6 print(check(19))
- 3 What is printed?
- 1 def f(x):
- 2 return x * 3
- 3 def g(x):
- 4 return x - 3
- 5 print(g(f(7)))
- 4 What is printed?
- 1 def double(n):
- 2 return n * 2
- 3 total = 0
- 4 for i in range(1, 4):
- 5 total += double(i)
- 6 print(total)
- 5 What is printed?
- 1 def perimeter(w, h):
- 2 return 2 * (w + h)
- 3 print(perimeter(3, 6) + perimeter(4, 5))
- 6 What is printed?
- 1 def bigger(a, b):
- 2 if a > b:
- 3 return a
- 4 return b
- 5 print(bigger(8, 10) * 2)
What your child practices
Your child builds careful code tracing. The skill is “Functions”: name a group of steps once and reuse it wherever it is needed.
- Grades and ages
- Grade 9, ages 14 to 15
- Time
- About 30 to 40 minutes
- Subject
- Coding
- Level
- Medium for Grade 9
- Answer key
- Yes, for grown-ups who sign in
- Printing
- 1 page, US Letter or A4, low-ink option
- Updated
How to use it
Work through the first program together, one line or arrow at a time. Then let your child work through the rest, showing their thinking on the page. It is pitched at the expected level for Grade 9, for practice after the skill has been taught.
An answer key comes with it as a separate page that grown-ups download after signing in.
Tip for grown-ups: Have your child write each variable's value beside its line as they trace.
Done on paper? A grown-up can record it on the child's page in PlayOwl; downloading alone doesn't count as finished.
Printable generator
Make your own printables
Make brand-new sheets like this one, with answer keys, using the printable generator that comes with a PlayOwl plan. This sheet stays free.