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
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules