Practice Error Types in CS Thinking

Use these practice problems to test your method after reviewing the concept explanation and worked examples.

Quick Recap

Error types are the main categories of mistakes that can occur in a program. The most common categories are syntax errors (the code is written incorrectly), runtime errors (the program crashes while running), and logic errors (the program runs but gives the wrong answer).

Some bugs stop the code from running, some crash it later, and some quietly give the wrong answer.

Showing a random 20 of 50 problems.

Example 1

medium
Which error type is most likely to slip into production unnoticed for months: syntax, runtime, or logic? Justify in one sentence.

Example 2

medium
Trace: `def f(x): return x/0`. Is `f` flawed at parse time, call time, or only when called with certain inputs?

Example 3

hard
A multi-threaded counter occasionally undercounts by 1 due to a race condition. Classify and explain why it is hard to detect.

Example 4

medium
A program prints leaderboard ranks 1, 2, 3, ..., 9, 10 but sorts strings, so the order is 1, 10, 2, 3, .... Classify and explain.

Example 5

easy
Which error type does a compiler/interpreter typically catch BEFORE the program runs at all?

Example 6

medium
Code: `total = total + 'x'` adds a string to a number, raising a TypeError when the line runs. Classify the error type.

Example 7

medium
A program reads `int(input())` and the user types `3.5`, throwing ValueError. Is the deeper bug a logic error or only a runtime error?

Example 8

easy
A function that should return the maximum of two numbers always returns the minimum. The program runs without crashing. Classify the error.

Example 9

medium
A sort function returns a list that is reversed instead of sorted ascending. The code runs cleanly. Classify it and describe how to detect it.

Example 10

challenge
You are handed three failure reports: (1) red squiggle in the editor before run, (2) intermittent crash under load, (3) wrong totals on the monthly summary. Pair each with syntax, runtime, or logic and rank by typical cost to fix in production.

Example 11

hard
Sort by category: (a) missing `import math` (NameError when `math.sqrt` is called), (b) `if x < 0 print(x)` lacks the colon, (c) `return n*(n+1)//2 - 1` in a sum function.

Example 12

easy
A program accesses `list[10]` on a list of length 5 and crashes. What error type is this?

Example 13

medium
Trace: `nums=[3,1,2]; nums.sort; print(nums[0])`. Is anything wrong, and if so what type?

Example 14

medium
In Python, indenting one line of a block incorrectly causes 'IndentationError'. Which of the three main categories does this belong to?

Example 15

medium
A program computes an average as `sum / count` but `count` is 0 for an empty list, crashing. Classify the error AND name the deeper category if the empty-list case was never considered.

Example 16

easy
Fill in: A ____ error prevents the program from starting because the parser cannot understand the code.

Example 17

medium
Three bugs are found: (1) unmatched bracket, (2) accessing a null/None object, (3) a tax rate of 0.05 typed as 0.5. Classify each.

Example 18

medium
A bank program computes interest correctly in testing but occasionally loses a cent due to floating-point rounding. Classify the error and explain why it is the hardest type to catch.

Example 19

easy
Classify this error: dividing by zero, `x = 10 / 0`, which crashes mid-execution.

Example 20

medium
Trace and classify: `def avg(xs): return sum(xs)/len(xs)` is called as `avg([])`. What error fires and what category?