Introduction to Tracing and
Debugging
Python 1
What is Tracing?
● The process where you go read code line-by-line and determine its
behaviour
● We have done this in the past in some in-class exercises such as: "What
does this code output?"
● However, sometimes the code will become more and more complex, but
you will still have to understand how it works
● Tracing would also include keeping proper records of variables and their
values as well as how they change.
Why do we learn tracing?
● When you have the tracing skills, you
would be able to easily identify the
source of many errors (known as bugs)
in your code and fix them.
○ Identifying bugs and fixing them is
known as debugging.
● Even at the professional level,
programmers make mistakes in their
code! What also matters is how they can
determine the mistake and fix it.
Tracing Examples
m = 30
n = 10
x = m // n + 3
m //= 2 Visualizer
n += 2
print(x, m, n)
x += m // 4
n = x + m
print(x, m, n)
Tracing Handout
Get a tracing worksheet