A breakpoint marks a program location where the debugger pauses execution before the associated code runs. The pause lets you inspect variable values and step through relevant lines instead of tracing an entire large program. section 8.2.2
Use a breakpoint to focus debugging on the part of a program that matters:
- Place it by clicking to the left of a code line in VS Code; a red dot indicates that it is set. section 8.2.2
- Start debugging with Run > Start Debugging. section 8.2.2
- Inspect values, use Step Over to advance line by line, or use Continue to reach the next pause. section 8.2.2 section 8.5
- Add more breakpoints when needed, or remove one by clicking its red dot again. section 8.2.2
Finding a missing final update
A doctest expects most_students to return 4 but gets 3. Set a breakpoint at the count update, inspect count as the debugger pauses, continue through the loop, and discover that the final consecutive group is not compared with max_count. Moving the comparison into the student branch fixes the edge case. section 8.5
Listing 8.4 Incorrect count_words function for debugging
def count_words(words):
count = 0
for word in words:
if "dan" in word.lower():
count += 1
return count
words = ["Dan", "danger", "Leo"] #1
print(count_words(words)) #1
Inspect the deliberately incorrect count_words function used to demonstrate breakpoint placement, stepping, and variable inspection. section 8.2.2





