Find a bug and check the repair
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.
Want more background?
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.
Debugging moves from observation to a small hypothesis, then to evidence.
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
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
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
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
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
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.
See how it works.
Fictional example: an accidental zero in the workshop settings reveals a missing guard.
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.
Did you cover these?
- Invalid checks occur before division.
- Negative and zero divisor cases return None.
- Original valid case still returns 5.
What to finish
A bug note, guarded function and five expected-result checks.
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.
Quick knowledge check
Answer all 3 questions. Get at least 2 right and the lesson completes automatically.
You’ll get an explanation for each answer. Signed in? Your results save to your account.
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 checkTools, 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.
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.
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.