Coding worksheet · Coding
Trace the lists: indexes, loops and append · Grades 9–11
Read 6 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.
- Grades 9–11 · ages 14 to 17
- Easy
- 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 = [14, 10, 20, 3, 19]
- 2 print(nums[1] + nums[-2])
- 2 What is printed?
- 1 nums = [14, 34, 33, 36, 12]
- 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 = [8, 3, 7]
- 2 for i in range(len(nums)):
- 4 print(nums)
- 4 What is printed?
- 1 nums = [11, 6, 14, 2, 16, 4]
- 2 total = 0
- 4 if n > 9:
- 5 total += n
- 6 print(total)
- 5 What is printed?
- 1 values = []
- 2 for i in range(5):
- 4 print(len(values), values[-1])
- 6 What is printed?
- 1 nums = [19, 17, 17, 13]
- 2 print(nums[2] + nums[-2])
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
- Grades 9–11, ages 14 to 17
- Time
- About 25 to 35 minutes
- Subject
- Coding
- Level
- Easy for Grades 9–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 easier sheets for Grades 9–11, 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.