Skip to content
PlayOwl

Coding worksheet · Coding

Trace the conditions: which branch runs? (warm-up) · Grade 7

Read 6 short Python programs about if, elif and else with and/or conditions and work out by hand what each one prints or the final value of a variable. Builds careful code tracing.

  • Grade 7 · ages 12 to 13
  • Easy
  • 35 to 45 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 bigger(a, b):
  • 2 if a > b:
  • 3 return a
  • 4 return b
  • 5 print(bigger(5, 7) * 2)
  • 2 What is printed?
  • 1 nums = [6, 20, 2, 3, 20]
  • 2 count = 0
  • 3 for n in nums:
  • 4 if n < 8:
  • 5 count += 1
  • 6 print(count)
  • 3 What is printed?
  • 1 age = 11
  • 2 height = 158
  • 3 if age >= 10 and height >= 126:
  • 4 print("ride")
  • 6 print("wait")
  • 4 What is printed?
  • 1 total = 0
  • 2 for i in range(1, 6):
  • 3 if i % 2 == 1:
  • 4 total += i
  • 5 print(total)
  • 5 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(28))
  • 6 print(check(13))
  • 6 What is big at the end?
  • 1 a = 20
  • 2 b = 6
  • 3 if a > b:
  • 4 big = a
  • 6 big = b

What your child practices

Your child builds careful code tracing. The skill is “Conditions”: use if/else to respond to situations.

Grades and ages
Grade 7, ages 12 to 13
Time
About 35 to 45 minutes
Subject
Coding
Level
Easy for Grade 7
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 Grade 7, 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.