Skip to content
PlayOwl

Coding worksheet · Computers & Digital Literacy

Trace the functions: what is returned? · Grade 8

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 8 · ages 13 to 14
  • Medium
  • 30 to 40 minutes
  • 1 page
  • Free
Paper

The answer key is a separate page for grown-ups. Sign in to download it.

Make another one like this

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 f(x):
  • 2 return x * 3
  • 3 def g(x):
  • 4 return x - 4
  • 5 print(f(g(6)))
  • 2 What is printed?
  • 1 def bigger(a, b):
  • 2 if a > b:
  • 3 return a
  • 4 return b
  • 5 print(bigger(2, 3) * 3)
  • 3 What is printed? Write each line.
  • 1 def check(n):
  • 2 if n % 2 == 0:
  • 3 return "fits"
  • 4 return "left over"
  • 5 print(check(18))
  • 6 print(check(11))
  • 4 What is printed?
  • 1 def double(n):
  • 2 return n * 2
  • 3 total = 0
  • 4 for i in range(1, 5):
  • 5 total += double(i)
  • 6 print(total)
  • 5 What is printed?
  • 1 def boost(x):
  • 3 print(boost(4))
  • 6 What is printed?
  • 1 def area(w, h):
  • 2 return w * h
  • 3 print(area(5, 3) + area(2, 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 8, ages 13 to 14
Time
About 30 to 40 minutes
Subject
Computers & Digital Literacy
Level
Medium for Grade 8
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 8, 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.