0

I am new to python and Ipython . I want to debug code in my Ipython notebook and want to find out total number of steps/iterations. But i don't know how to do debug. I have watched youtube videos but that showed debugging in pycharm but i am unable to find any proper video with significant detail in regards to Ipyhton.

My code is below

for i in range(4):
    for j in range(i+1):
        print('*',end='')
        
    print()

I have also attached snapshot of my notebook enter image description here

wjandrea
  • 28,235
  • 9
  • 60
  • 81
LECS
  • 121
  • 12
  • Hey there, I am not sure what you mean by debugging since your code seems fine. if you are interested to know the total iteration number maybe you can add `total_count` as a global variable and increment it each iteration. – Vae Jiang Jul 30 '22 at 14:38
  • I don't use Jupyter, but I googled `how to debug in jupyter` and found this: [What is the right way to debug in iPython notebook?](/q/32409629/4518341) Does that answer your question? BTW note that "IPython Notebook" is now called "Jupyter Notebook". – wjandrea Jul 30 '22 at 15:09

1 Answers1

0

you can use set_trace()

from IPython.core.debugger import set_trace

for i in range(4):
  for j in range(i+1):
    set_trace()
    print('*',end='')
    
print()

important commands :
n -> next line
c -> continue until the next breakpoint
q -> quits
also see links below:
1-medium
2-stackoverflow

Galaxy
  • 172
  • 9