<jupyter_start><jupyter_text>Debugging Debbuging your code helps you to localize the source of error and correct them. Debugging tools can also be useful to better understand your code.<jupyter_code>import numpy as np
def math_operations(x):
    
    sq = x**2
    sq += sq
    sq = np.sin(sq)
    
    return sq
math_operations(4)
math_operations('4')
%debug
%pdb on
math_operations('4')
%pdb off<jupyter_output>Automatic pdb calling has been turned OFF<jupyter_text>we can also add breakpoints in the code that are used to stop the code at any point<jupyter_code>from pdb import set_trace
def math_operations(x):
    
    #modify your code to stop at any point
    set_trace()
    sq = x**2
    sq += sq
    sq = np.sin(sq)
    
    return sq
math_operations('4')
def math_operations(x):
    
    #modify your code to stop at any point
    set_trace()
    sq = x**2
    sq += sq
    
    #you can add more than one
    set_trace()
    sq = np.sin(sq)
    
    return sq
math_operations(4)
for i in range(3):
    
    set_trace()
    print(i)<jupyter_output>> [0;32m<ipython-input-26-4de6acaabb02>[0m(4)[0;36m<module>[0;34m()[0m
[0;32m      1 [0;31m[0;32mfor[0m [0mi[0m [0;32min[0m [0mrange[0m[0;34m([0m[0;36m3[0m[0;34m)[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m
[0m[0;32m      2 [0;31m[0;34m[0m[0m
[0m[0;32m      3 [0;31m    [0mset_trace[0m[0;34m([0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
[0m[0;32m----> 4 [0;31m    [0mprint[0m[0;34m([0m[0mi[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
[0m
{'fraction_non_alphanumeric': 0.17570215545395165, 'fraction_numerical': 0.09274983670803397, 'mean_word_length': 3.990228013029316, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '657385', 'license': 'MIT', 'n_tokens_mistral': 772, 'n_tokens_neox': 675, 'n_words': 137, 'path': 'debugging.ipynb', 'repo_name': 'dguari1/BME3240_2021', 'size': '1531'}