Bug Hunters
Every program has bugs. Great programmers find them.
Year 7 Computer Science — Debugging
The Buggy Sandwich
Teacher makes a sandwich — but with bugs:
- Puts filling between slices first
- Then spreads butter on the outside of the bread
- Eats it before cutting
What types of errors were these? Which steps were wrong order? What was missing?
Three Types of Bugs
Wrong Order
All steps present, wrong sequence
Missing Step
An essential step has been left out
Logic Error
A condition or value is incorrect
Your worksheet has one of each. Find them all!
Algorithm 1: Making Toast
Step 1: Put bread in the toaster
Step 2: Eat the toast
Step 3: Wait for the toaster to pop
Step 4: Spread butter on the toast
Step 5: Take the toast out of the toaster
Trace through this exactly. What goes wrong?
Algorithm 2: Combination Lock
Step 1: Turn dial RIGHT to first number
Step 2: Turn dial LEFT to second number
Step 3: Pull the lock open
Try this on a real combination lock. What's missing?
(Hint: a real combination lock needs 3 numbers...)
Algorithm 3: Biggest Number
numbers = [3, 7, 2, 9, 1]
biggest = 0
FOR EACH number IN numbers:
IF number < biggest:
biggest = number
PRINT biggest
Trace with [3, 7, 2, 9, 1]. What does it print? What should it print?
The Debugging Process
- 1. Trace carefully — follow every step exactly
- 2. Note what ACTUALLY happens — not what you expect
- 3. Find the divergence — where does actual ≠ expected?
- 4. Fix the minimum — change only what's broken
- 5. Test — does it work now? Are there more bugs?
Key Takeaway
Debugging requires systematic tracing — follow every step, check every value, never assume.
Professional programmers spend ~50% of their time debugging.
A bug is a problem to solve — not a reason to start over.
1 / 8
← → or click to advance