Run Python in your browser and get a step-by-step trace table, with exam blanks, a study mode and exports.
Run Python and get a line-by-line trace table, then fill it in yourself in Study mode.
This tool needs JavaScript.
A trace table records a dry run: you follow a program one line at a time and write down each value as it changes. It shows what an algorithm does and where it goes wrong. There is a column for each variable you are following, usually one for output, and sometimes one for the line number or a condition.
A while loop tests its condition before every pass, including the last test, which is False and ends the loop. An if line only tests: it changes no variable, so on its own it usually adds no row. In Python, for i in range(3) gives i the values 0, 1 and 2, never 3. To see each test here, set Rows to Every line, or add the Condition column from the Columns menu.
This program looks along a list for 15 and stops when it finds it. The line numbers start at 1.
items = [4, 8, 15, 16, 23, 42] target = 15 found = False i = 0 while i < len(items) and not found: if items[i] == target: found = True else: i = i + 1 print(found, i)
The values 4 and 8 do not match, so line 9 adds 1 to i twice. Then items[2] is 15, line 7 sets found to True, and the next loop test fails. i stays at 2 because the else branch does not run.
The tool adds a column for the watched expression i < len(items), which you don’t need.
Open this example (it replaces the code in the editor)
Usually not. The common layout adds a value only when a variable changes or something is printed. Some questions ask for a row for every line or every pass, so follow the instructions and the table printed in your question.
A blank usually means the value is unchanged. In this tool, Exam blanks shows a value only where it changes, and Carry forward repeats the current value in every row.
Run a program, then choose Study mode. Cells are hidden for you to fill in, and you can check your answers, ask for a hint or reveal one cell at a time.