Coding worksheet · Coding
Trace the functions: what is returned? (stretch) · Grade 11
Read 7 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 11 · ages 16 to 17
- Hard
- 35 to 45 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 f(x):
- 2 return x * 2
- 3 def g(x):
- 4 return x - 1
- 5 print(g(f(8)))
- 2 What is printed?
- 1 a = 64
- 2 b = 24
- 3 while b != 0:
- 4 t = b
- 6 a = t
- 7 print(a)
- 3 What is printed?
- 1 def stack(n):
- 2 total = 0
- 3 for i in range(1, n + 1):
- 4 total += i
- 5 return total
- 6 print(stack(5))
- 4 What is printed?
- 1 def times_four(n):
- 2 return n * 4
- 3 total = 0
- 4 for i in range(1, 3):
- 5 total += times_four(i)
- 6 print(total)
- 5 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(18))
- 6 print(check(16))
- 6 What is printed?
- 1 def frame(word, edge):
- 2 return edge + word + edge
- 3 print(len(frame("meadow", "##")))
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 11, ages 16 to 17
- Time
- About 35 to 45 minutes
- Subject
- Coding
- Level
- Hard for Grade 11
- 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 harder sheets for Grade 11, best once the basics of the skill are secure.
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.