: : , debug start of program : : , debug start of factorial( : : , debug is total is : : , debug is total is : : , debug is total is : : , debug is total is : : , debug is total is : : , debug is total is : : , debug end of factorial( : : , debug end of program the factorial(function is returning as the factorial of which isn' right the for loop should be multiplying the value in total by the numbers from to but the log messages displayed by logging debug(show that the variable is starting at instead of since zero times anything is zerothe rest of the iterations also have the wrong value for total logging messages provide trail of breadcrumbs that can help you figure out when things started to go wrong change the for in range( )line to for in range( ):and run the program again the output will look like this : : , debug start of program : : , debug start of factorial( : : , debug is total is : : , debug is total is : : , debug is total is : : , debug is total is : : , debug is total is : : , debug end of factorial( : : , debug end of program the factorial( call correctly returns the log messages showed what was going on inside the loopwhich led straight to the bug you can see that the logging debug(calls printed out not just the strings passed to them but also timestamp and the word debug don' debug with the print(function typing import logging and logging basicconfig(level=logging debugformat'%(asctime) %(levelname) %(message) 'is somewhat unwieldy you may want to use print(calls insteadbut don' give in to this temptationonce you're done debuggingyou'll end up spending lot of time removing print(calls from your code for each log message you might even accidentally remove some print(calls that were being used for nonlog messages the nice thing about log messages is that you're free to fill your program debugging