Skip to content
PlayOwl

Coding worksheet · Coding

Trace the loop: what is printed? (practice) · Grades 6–8

Read 6 short Python programs about for and while loops and work out by hand what each one prints or the final value of a variable. Builds careful code tracing.

  • Grades 6–8 · ages 11 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? Write each line.
  • 1 for i in range(3, 6):
  • 2 What is printed?
  • 1 nums = [40, 23, 21, 32, 3]
  • 2 best = nums[0]
  • 3 for n in nums:
  • 4 if n > best:
  • 5 best = n
  • 6 print(best)
  • 3 What is printed?
  • 1 nums = [5, 8, 7]
  • 2 for i in range(len(nums)):
  • 4 print(nums)
  • 4 What is printed?
  • 1 def triple(n):
  • 2 return n * 3
  • 3 total = 0
  • 4 for i in range(1, 4):
  • 5 total += triple(i)
  • 6 print(total)
  • 5 What is printed?
  • 1 total = 0
  • 2 for i in range(1, 6):
  • 3 if i % 2 == 1:
  • 4 total += i
  • 5 print(total)
  • 6 What is printed?
  • 1 n = 42
  • 2 steps = 0
  • 3 while n > 1:
  • 5 steps += 1
  • 6 print(steps)

What your child practices

Your child builds careful code tracing. The skill is “Loops”: use repetition to shorten programs.

Grades and ages
Grades 6–8, ages 11 to 14
Time
About 30 to 40 minutes
Subject
Coding
Level
Medium for Grades 6–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 Grades 6–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.