Editor settings

General settings

Save settings

Learn to program with Python

Inspect values with print function #

The print() function is a valuable tool for debugging Python code. It allows you to inspect the values of variables, track the flow of your program, and identify potential issues.

To examine the values of variables at specific points in your code, insert print statements that display the variable values. For example, you can print the value of a variable x by using print(x). This helps you verify if the variable has the expected value and identify any inconsistencies.


Exercise #

  • Uncomment the code on lines 5 and 7 to see how to use print() for debugging.

Tests #

  • In each iteration, the program should print the current value of variable num.
  • In each iteration, the program should print the current value of variable total
Output will be displayed here