Coding worksheet · Computers & Digital Literacy
Trace the functions: what is returned? · Grades 10–12
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.
- Grades 10–12 · ages 15 to 18
- Easy
- 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(len(frame("pencil", "**")))
- 2 What is printed?
- 1 def grow(x):
- 3 print(grow(4))
- 3 What is printed?
- 1 def area(w, h):
- 2 return w * h
- 3 print(area(6, 5) + area(4, 5))
- 4 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(8))
- 6 print(check(6))
- 5 What is printed?
- 1 def triple(n):
- 2 return n * 3
- 3 total = 0
- 4 for i in range(1, 3):
- 5 total += triple(i)
- 6 print(total)
- 6 What is printed?
- 1 def f(x):
- 2 return x * 3
- 3 def g(x):
- 4 return x - 1
- 5 print(f(g(7)))
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
- Grades 10–12, ages 15 to 18
- Time
- About 30 to 40 minutes
- Subject
- Computers & Digital Literacy
- Level
- Easy for Grades 10–12
- 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 one of the easier sheets for Grades 10–12, good as a warm-up or a first look at the skill.
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.