What you will learn
  • Explain evidence-based debugging in plain language.
  • Trace information from input to output.
  • Test one subsystem independently.
  • Recognize a common failure and respond safely.
  • Modify the example without changing several variables at once.

The central idea: evidence-based debugging

A traceback records where an exception occurred and the calls that led there. Debugging starts with the final exception type and message, reproduces the problem, and tests the smallest plausible cause.

Treat the system as a chain of observable inputs, explicit processing, a decision, and an output. That makes the design easier to explain and gives you a place to test when something fails. A working result is not enough: record what input produced it and what evidence shows the result is correct.

Follow the information through the system

Read the diagram from left to right. Each arrow is a boundary where data, electrical signals, or commands move between parts. Test those boundaries separately before combining the whole system.

A program fails with ValueError while converting twelve to an integer. The traceback identifies the conversion line; input validation fixes the cause rather than hiding the error.

  • Read the exception type before editing.
  • Keep the failing input.
  • Catch only errors you can handle meaningfully.
Reproduce → read last traceback line → inspect named line → test one cause → rerun

A small working example

Run this example exactly as shown before modifying it. Predict the output first, compare that prediction with the real result, and change only one part at a time.

Python
text = "twelve"
try:
    number = int(text)
except ValueError:
    print(f"{text!r} is not a whole number")

The handler catches only the expected conversion failure and reports the rejected value.

Expected result: 'twelve' is not a whole number

Test before you trust the result

Start with a normal case, then test a boundary case and a failure case. For software, try empty, unexpected, and extreme inputs. For hardware, begin with wheels raised or actuators disconnected, keep a physical power switch within reach, and verify safe stopping behavior.

Write down the expected result before each test. If the observation differs, stop and find the first boundary where the expected signal disappeared. This method is slower than changing many things at once, but it produces evidence instead of guesses.

  • Test one input with a known value.
  • Observe the intermediate value before the final action.
  • Confirm a safe response when input is missing or invalid.
  • Repeat the same test to check consistency.

Important terms

Exception
An object representing an error detected during execution.
Traceback
A report of the active call stack when an exception occurs.
ValueError
An exception raised when a value has the right general type but an invalid form.
Breakpoint
A place where a debugger pauses execution.
Regression
A previously working behavior that later breaks.

Mini project: practice evidence-based debugging

  1. Run a program with a known bad input.
  2. Copy the last traceback line.
  3. Locate the referenced source line.
  4. State one hypothesis.
  5. Make one change and rerun the original input.

Common mistakes and debugging

  • Editing before reading the exception message.
  • Catching every exception with bare except.
  • Changing multiple lines at once.
  • Deleting the failing test after the program works.

Independent challenge

Add input validation to a positive-whole-number prompt. Keep asking after invalid text, but stop after three failed attempts with a clear message.

Check your understanding: 10 questions

  1. What is the main purpose of evidence-based debugging?

  2. What does “Exception” mean in this lesson?

  3. How is “Traceback” used?

  4. Why should you test one boundary or subsystem at a time?

  5. What should the system do when an input is missing or invalid?

  6. In your own words, what does “Exception” mean?

  7. In your own words, what does “Traceback” mean?

  8. In your own words, what does “ValueError” mean?

  9. In your own words, what does “Breakpoint” mean?

  10. In your own words, what does “Regression” mean?

Quiz answers

Reveal all 10 answers after your attempt
  1. A traceback records where an exception occurred and the calls that led there. Debugging starts with the final exception type and message, reproduces the problem, and tests the smallest plausible cause.
  2. An object representing an error detected during execution.
  3. A report of the active call stack when an exception occurs.
  4. It reveals where the expected value or behavior first changes, so debugging is based on evidence.
  5. It should reject the input, report the problem, or move to a documented safe state instead of guessing.
  6. An object representing an error detected during execution.
  7. A report of the active call stack when an exception occurs.
  8. An exception raised when a value has the right general type but an invalid form.
  9. A place where a debugger pauses execution.
  10. A previously working behavior that later breaks.

Summary

evidence-based debugging becomes manageable when you identify the input, processing, decision, output, and evidence of success. Build the smallest version, test it, then make one measured change.

Continue learning

Continue to the next lesson, which builds on this model with one additional capability.

Choose a connected learning path

Sources and further reading

Prepared 2026-10-02. Editorially completed for the course. Software examples are designed for current Python 3; verify board, operating-system, library, and hardware details against the linked primary documentation before a physical build.

GO DEEPER

Extra reading & source documents

Optional reading alongside the lessons. These sources do not add to your course lesson count.

Explore the AI model guides →