The Life Starter
0 of 6 complete0%
Course Library · Lesson 5 of 6
Digital · Guided lesson

Find a bug and check the repair

About 38 minutes · 8 reading + 30 practice and checks
Time includes reading, practice, and questions. Extra videos or further study are optional.
See this course’s project requirements

Build a supply-kit calculator, check it with five test cases, and explain how to use it. Combine the work you complete across the six lessons.

Keep your working files in your own notebook or software. Save a private description, checklist, and work link in My Proof.

What to include

  • State numeric input rules and invalid-input behavior.
  • Include a working function, conditional guard and loop over a list.
  • Show original, changed, empty and invalid-input reasoning.
  • Retain five explicit tests with expected results.
  • Provide complete code, expected output and a handoff note.

Review and revise

Use these criteria to check your work and choose what to improve.

  • Correctness: valid quantities produce independently checked kit counts.
  • Reasoning: traces explain assignment, branches and repeated work.
  • Testing: normal and invalid cases support the claimed behavior.
  • Handoff: supported inputs and limitations are clear.
Open the full course project
Want more background?
Before you begin

The idea in everyday life

Programs can stop with an error or run successfully while producing an incorrect answer. Both deserve careful investigation. You will add a deliberate invalid-input result to the kit function, then test that ordinary inputs still work. This is practice on a tiny local program, so no real system access or debugging service is needed.

The idea

Debugging moves from observation to a small hypothesis, then to evidence.

Try it

One step at a time.

Use the sample or information you have permission to use. Keep your work as you go. You can pause between steps.

  1. 1

    Reproduce the current function with per_kit=0 by tracing the division or optionally running it. Record that zero division prevents a valid kit count; do not label the expected error as a successful answer.

  2. 2

    Choose a clear invalid-input behavior for this beginner program: return None for negative supplies or a nonpositive per_kit. State that this guard assumes numeric whole-number inputs and does not validate arbitrary text.

  3. 3

    Add the guard—a check that rejects invalid input—before division. Use or because either invalid condition is enough to reject the request. Calculate only after this check passes.

  4. 4

    Create tests for (23,4), (0,4), (-1,4), (9,0) and (9,-2). Predict 5, 0, None, None and None. Use the explicit assertions in the example or compare a paper result table.

  5. 5

    Rerun the ordinary case after changing validation. Save the failing case, the repair and the new evidence. A repair that rejects every input would prevent the error but break the promised useful behavior.

Example

See how it works.

Fictional example: an accidental zero in the workshop settings reveals a missing guard.

python
def complete_kits(supplies, per_kit):
    if supplies < 0 or per_kit <= 0:
        return None
    return supplies // per_kit

assert complete_kits(23, 4) == 5
assert complete_kits(9, 0) is None
print("Two checks passed")

The second assertion checks the agreed invalid result, not a made-up kit count. Both assertions succeed, producing the printed message. If an assertion fails, stop and compare actual behavior with its expected value. These checks establish only the tested cases; text inputs, decimal quantities and very different requirements remain outside this limited function contract.

Check your work

Did you cover these?

  • Invalid checks occur before division.
  • Negative and zero divisor cases return None.
  • Original valid case still returns 5.
Your work

What to finish

A bug note, guarded function and five expected-result checks.

Common mistake

Watch for this

Changing several things at once or treating an error-free run as proof of correctness.

How can I tell I understand it?

Explain the smallest failing case and show that a valid case still works.

Try 3 questions

Quick knowledge check

Answer all 3 questions. Get at least 2 right and the lesson completes automatically.

Not yet passed

You’ll get an explanation for each answer. Signed in? Your results save to your account.

1For supplies=-2 and per_kit=3, what should the guarded function return?
2The contract accepts nonnegative supplies and positive per_kit. After a repair, (9,0) returns None as intended, but the previously valid (20,4) also returns None. What does this show?
3The contract counts complete kits. An assertion expects 6 for complete_kits(20,4). What should you check first?
0 of 3 answeredApply the lesson to a short question, then review the explanation.
5
Finish this lesson

Pass the check. We’ll save the progress.

Answer all 3 questions above and get at least 2 right. You can review the explanations and try again.

Go to the knowledge check
Tools, templates, and lesson sources

Tools and templates

Tools open in a new tab so you can keep your place here.

Sources and further reading

Explore the references behind this lesson.

Harvard CS50 — Introduction to Programming with Python
Source & access notes · checked 2026-09-10

Opened the course overview and Week 0 page; verified coverage of variables, conditionals, loops, exceptions and testing. Optional deeper study, not a source of copied exercises.

Access: OpenCourseWare is free to read/watch. External assignment submission requires an edX account; optional verified/professional certificates use separate enrollment and may cost money. No Harvard affiliation or credit is offered here.

Reuse: Linked for reference. Examples, activities and assessments here are original; free access alone does not grant permission to reuse source text or branding.

Python documentation — An Informal Introduction
Source & access notes · checked 2026-09-10

Opened official Python 3 tutorial; read arithmetic, assignment, strings, lists and indexing sections.

Access: Free public reading; no account or certificate is required for this Life Starter course.

Reuse: Linked for reference. Examples, activities and assessments here are original; free access alone does not grant permission to reuse source text or branding.

Report a problem with this lesson

Tell us what went wrong. Please leave out personal information and private project contents.

No sign-in needed.