Bug Hunters Worksheet
STUDENT MISSION LOG // LEVEL 1
Bug Hunters Worksheet
NAME:
DATE:
CLASS:
Apply your debugger training to identify common runtime exceptions, trace state mutations, and isolate logical bugs.
A SPOT THE EXCEPTION (Runtime Investigations)
Analyze each broken snippet. Identify the exact **Exception Type** (e.g., IndexError, KeyError, TypeError) and write a 1-sentence **explanation & fix**.
# Case #101
inventory = {"apples": 5, "pears": 3} item = "bananas" qty = inventory[item] print("Total qty:", qty)
1. IDENTIFIED EXCEPTION TYPE:
2. WHY DID IT CRASH & HOW WOULD YOU PREVENT IT?
# Case #102
level = 4 msg = "You are at level " + level print(msg)
1. IDENTIFIED EXCEPTION TYPE:
2. WHY DID IT CRASH & HOW WOULD YOU PREVENT IT?
B TRACE TABLE TRAINING (Logical Debugging)
Trace the values of variables as Python executes this loop. Fill in the empty table rows step-by-step.
// TRACE CODE CHASSIS
1 val = 15 2 steps = [1, 3] 3 for num in steps: 4 val -= num 5 val *= 2 6 print(val)
⚠️ Remember: Keep track of every iteration! Write down intermediate expressions to make sure you get the correct arithmetic.
STUDENT LOGGING MATRIX PENDING INPUT
| Step | Line | num | val |
|---|---|---|---|
| 0 (Init) | 1-2 | - | 15 |
| 1 (Iter 1) | |||
| 2 | |||
| 3 (Iter 2) | |||
| 4 | |||
| 5 (Final Output) | Prints: |
PYTHON BUG HUNTERS — MISSION LOG 1 // IDENTIFYING & TRACING
PAGE 1 OF 2
STUDENT MISSION LOG // LEVEL 2
LENNY NOW HAS EDITABLE ARTIFACTS!
STATION: LOGIC LAB
SCORE: 100 / 100
C STRATEGIC PRINT INSTRUMENTATION
Examine this logic error. The developer wants to count how many words in a list start with letter "a", but it keeps printing 0.
Matrix Chassis v1.0.1 SHINY // GREEN
# Buggy Code Chassis
1 words = ["apple", "banana"] 2 count = 0 3 for w in words: 4 first_letter = w[1] 5 if first_letter == "a": 6 count += 1 7 print("A counts:", count)
1. At which line number would you insert a diagnostic print() statement to check if the loop is selecting the correct character?
2. Write the exact line of Python code for a diagnostic print statement that prints the current word w and its checked first_letter:
D IDE DEBUGGER ACTION MATRIX
Circle or check the correct tool behavior depending on your current target goal during interactive debugging.
1
Your code execution is paused on Line 8, which is: scores_sum = aggregate(score_list). You suspect there is a logical calculation bug inside the aggregate function. Which debugger control should you click next?
[ ] Step Over [ ] Step Into [ ] Resume/Cont
2
You have set a red breakpoint at Line 15. The program is currently paused on Line 15. You have diagnosed the variables mentally, fixed the design logic, and now want to allow the script to execute completely to the end without checking any more single lines. Which debugger control should you click next?
[ ] Step Over [ ] Step Into [ ] Resume/Cont
E CODE SURGERY (Rewrite to Cure)
Rewrite the buggy loop from Section C so it operates correctly, selects the correct first letter, and outputs the accurate count (1). Keep your work clean...
PYTHON BUG HUNTERS — MISSION LOG 2 // CODESMITH REPAIRS
PAGE 2 OF 2









