Practice Debugging in CS Thinking
Use these practice problems to test your method after reviewing the concept explanation and worked examples.
Quick Recap
The systematic process of finding, diagnosing, and correcting errors (bugs) in a program. Debugging involves reproducing the problem, isolating its cause through testing and inspection, applying a targeted fix, and verifying the fix resolves the issue without introducing new problems.
Detective workβobserve the wrong output, form a hypothesis, test it, then fix what's wrong.
Showing a random 20 of 50 problems.
Example 1
easyA function works for input but crashes for input . What category of test catches ?
Example 2
medium`total = 0; FOR i = 1 TO 4: total = total + i; OUTPUT total`. What does it print?
Example 3
easyA code uses `if name = 'Sam':` and errors. What's wrong?
Example 4
mediumThe code `SET i = 0; WHILE i <= 5: OUTPUT i` prints how many numbers?
Example 5
challengeA buggy function returns `nums[i+1]` where nums has length and i runs up to . What error happens at the last iteration and how do you fix the index bound?
Example 6
mediumA loop `i = 0; while i < 5: print(i)` never stops. What's missing?
Example 7
mediumThis code should print numbers 1 to 5 but has a bug: SET i = 1. WHILE i < 5: OUTPUT i. i = i + 1. Find and fix the bug.
Example 8
easyWhat is the second step (after reproducing) in systematic debugging?
Example 9
mediumA bug only happens on the build server, not your laptop. What general kind of factor often causes this?
Example 10
mediumOutput is right for input 5 but wrong for input 0. Which test category caught this?
Example 11
medium`for item in items: items.remove(item)`. Why is this dangerous?
Example 12
mediumA test passes locally but fails on the build server. Changing one variable at a time, you find it's the OS file path separator. What debugging principle found it?
Example 13
hardA function reads a global config and behaves differently between test and prod. What is the hidden coupling?
Example 14
easyA function returns the wrong answer. To isolate the cause, what tool prints intermediate values?
Example 15
easyA bug keeps coming back in different forms. What did the previous fix likely address?
Example 16
easyWhat does 'reproduce the bug' mean?
Example 17
medium`def avg(nums): return sum(nums)/len(nums)`. Calling `avg([])` errors. What's the edge case and a fix?
Example 18
easyWhat is the term for an error in a program?
Example 19
challengeCode reads a global `config` and behaves differently in tests vs production. What hidden factor is causing the inconsistency?
Example 20
medium`x = [1,2,3]; for i in x: x.append(i)`. Why is this dangerous?