Computer science · Grades 7–11
Python-style code tracing
Use a small table of variable values after each statement.
Understand the idea
Track values
Use a small table of variable values after each statement.
Range stops before the end
In Python, range(start, stop) excludes stop. These questions do not execute user-written code.
Examples and reasoning
Python: x = 4; x = x + 6. What is x?
10
10
Python: total = 0 for n in range(1, 5): total += n What is total?
1 + 2 + 3 + 4 = 10
10
Check your understanding
Python: len([2, 4, 8, 16, 32]). What value is returned?
Python: values = [7, 11, 15]. What is values[1]?
Python: 17 // 5. What value is returned?
Python: 17 % 5. What value is returned?
Answers and marking notes
Answers and marking notes
- 5
There are five entries.
- 11
Python list indexes begin at 0.
- 3
Integer floor division gives 3 for these positive integers.
- 2
17 = 3 × 5 + 2.
Further reading and review references
These are reference links, not copied exercises, institutional endorsement or proof of independent review.
Learning preview · teacher review required. Grade bands are approximate, not official curriculum alignment.