Tracing Guide | CMSC 105 Elementary Programming - Fall 2024

Tracing Guide

The ability to trace your code is essential for debugging. Given some arbitrary Python code, you should always be able to answer the questions:


Instructions

Trace the execution of a program by filling in a tracing table.

  1. In Step, number the step of execution.
  2. In Memory State, show the values of all variables currently in memory after the line has executed, e.g., x: 5
  3. In Next Line, write down the next line of code that will execute, e.g., 2.
  4. In Output, write down any text if any, that will be printed.

Tracing table:

Step Memory State Next Line          Output         
       
       
       
       






Example 1

Tracing Example 1

Step Memory State Next Line Output
1 x: 5 2  
2 x: 5, y: 10 3  
3 x: 5, y: 10, sum: 15 4  
4 x: 5, y: 10, sum: 15 Done The sum is 15






Example 2

Tracing Example 2

Step Memory State Next Line Output
1 x: 5 2  
2 x: 5 4  
3 x: 5 5  
4 x: 5, result = "Odd" 6  
5 x: 5, result = "Odd" Done Odd