CampusSpark
ORIGINAL CAMPUSSPARK GUIDE

Make a smaller debugging example

BeginnerExplanation · worked example · practice

Reduce the problem while keeping the failure reproducible.

  1. Record expected and actual behavior.
  2. Remove unrelated inputs and code until the failure remains small.
  3. Change one cause, rerun the same example and record the result.
If only an empty list fails, test [] separately before rewriting the whole function.

See the reasoning, step by step.

  1. Fictional function average([2,4]) returns 3, but average([]) raises division by zero. Record both results.
  2. The smallest reproducer is the empty list. Decide the intended behavior before changing code: reject it explicitly or return a documented sentinel.
  3. For a reject-empty contract, check that [] now raises a clear ValueError and [2,4] still returns 3. Keep both cases.

A mistake worth catching

The trap: Catching every exception and returning 0.

A better approach: Do not hide unrelated failures or invent a valid average for an empty set. Define the function contract first.

Check your reasoning

For an average function that must reject empty input, which proposed check targets the original empty-list failure?

Your turn: use the idea.

Your chosen contract rejects empty input. Write two test expectations without claiming you executed them.

Try it yourself first. This is a self-review task, not automatic marking.

Compare with a model answer

average([]) should raise ValueError with a clear message; average([2,4]) should return 3. These are proposed expectations until you actually run the tests.

Check your own work

Go deeper with the right source.

Supporting references and further reading. The worked examples above are original CampusSpark teaching material.

Python tutorial: errors and exceptions

Free language documentation; local setup and version differences matter.

Lesson and answer rationale reviewed 27 October 2026. A practice answer is not an official exam score.
Start a coding course

Learning support, not an official certificate, professional assessment or automatic grade. Use original provider requirements for your examination or application.

Private AI