Lesson 03 — Comments and Debugging
Comments explain code
A comment starts with #. Python ignores the comment when running the program.
# Explain what this program is doing.
print("Systems ready")
Output
Systems ready
Comments can make code more understandable, but they do not fix incorrect instructions.
Not all bugs are the same
A syntax error means Python cannot understand the code’s structure. For example:
print("Starting..."
Python reports an error because the parentheses are unbalanced.
A logic error means the program runs but produces the wrong behavior:
print("Task finished")
print("Task started")
Both instructions are valid. Their order might be incorrect for the intended task.
A debugging habit
- Read the expected behavior.
- Run the program and look closely at the error or output.
- Change one thing you believe is wrong.
- Run again and compare.
Practice: Fix the Messages
The starter has punctuation mistakes that prevent the program from running. Correct them so the program displays exactly:
Debugging in progress
Problem solved
Stop and think
- Does a program that runs without errors always produce the correct output?
- How can an error message help narrow down where a mistake happened?