Python Tutor

Python Tutor (http://pythontutor.com/) is a free educational tool created by Philip Guo. It helps students overcome a fundamental barrier to learning programming. A teacher or student can write a Python program in the Web browser and visualize what the computer is doing step-by-step as it executes the program.

image001

  • Copy and paste your code into the textbox. In this example, we use an infinite loop as our example (M&C4:  Infinite Loops).

pythontutor1

  • Click the Visualize Execution button to visualize your code step by step.

pythontutor2

  • Click Forward or other buttons to see different steps. In this example, when we go to the Step 48 and variable i is 106, the loop still has not terminated. The original intent of the code below is to terminate once i reaches 100.  However, variable i never does have the value of 100 and we have an infinite loop.

pythontutor3

  • In Python Tutor, one can see the values of all variables clearly.  In our example, Python Tutor gives a warning that “stopped after 300 steps to prevent possible infinite loop.”  This helps in the case of infinite loops.

image005 image006