Execute algorithm step by step in Jupyter
I am trying to show the execution of a Python program in Jupyter, step by step. For example, I can visualize the value of a variable in a program as in the following toy program: from IPython.display import display, clear_output from time import sleep def sum_first_integers(n): res = 0 for i in range(n+1): res += i clear_output(wait=True) display(res) sleep(.5) return res This shows the value of res at each step of the algorithm, and I added a sleep(.5) to be able to actually view the execution of the algorithm. My question is whether there exists a better way of performing this visualization: