Coding worksheet · Coding
Trace the lists: indexes, loops and append · Grade 12
Read 7 short Python programs about list indexes, len, append and loops over lists and work out by hand what each one prints or the final value of a variable. Builds careful code tracing.
- Grade 12 · ages 17 to 18
- Hard
- 25 to 35 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 nums = [1, 2, 9, 2]
- 2 for i in range(len(nums)):
- 2 What is printed?
- 2 for i in range(3):
- 4 print(values)
- 3 What is printed?
- 1 nums = [19, 15, 10, 2, 10, 12]
- 2 total = 0
- 3 for n in nums:
- 4 if n > 5:
- 5 total += n
- 6 print(total)
- 4 What is printed?
- 1 nums = [9, 9, 3]
- 5 What is printed?
- 2 for i in range(5):
- 3 values.append(i * i)
- 4 print(len(values), values[-1])
- 6 What is printed?
- 1 nums = [13, 12, 14, 3, 6]
- 2 count = 0
- 4 if n < 6:
- 5 count += 1
- 6 print(count)
What your child practices
Your child builds careful code tracing. The skill is “Variables”: use named values such as a score, lives or a timer that a program changes and checks.
- Grades and ages
- Grade 12, ages 17 to 18
- Time
- About 25 to 35 minutes
- Subject
- Coding
- Level
- Hard for Grade 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 harder sheets for Grade 12, 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.