Coding worksheet · Computers & Digital Literacy
Trace the strings: indexing and slicing (warm-up) · Grade 11
Read 6 short Python programs about string indexing, slicing and loops over letters 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
- Easy
- 20 to 30 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? Write each line.
- 1 for i in range(4, 0, -1):
- 2 What is printed?
- 1 text = "turtle"
- 2 result = ""
- 3 for ch in text:
- 4 result = ch + result
- 5 print(result)
- 3 What is printed?
- 2 count = 0
- 3 for ch in word:
- 4 if ch == "o":
- 5 count += 1
- 6 print(count)
- 4 What is printed?
- 1 def frame(word, edge):
- 2 return edge + word + edge
- 3 print(frame("window", "#"))
- 5 What is printed?
- 2 print(word[1:5])
- 6 What is printed? Write each line.
- 1 for i in range(1, 4):
What your child practices
Your child builds careful code tracing.
- Grades and ages
- Grade 11, ages 16 to 17
- Time
- About 20 to 30 minutes
- Subject
- Computers & Digital Literacy
- Level
- Easy 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 easier sheets for Grade 11, good as a warm-up or a first look at the topic.
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.