Package a calculation as a function
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
The kit calculation should work for several sessions without repeatedly editing hidden variables. Functions make the needed inputs visible and give a result back to the caller. This helps someone reuse your work safely. We will keep the interface small: an available supply count and the number of supplies required per kit.
A function is a named recipe with inputs and a returned result.
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
Write the function’s contract—its input rules and promised result: supplies is a nonnegative whole number, per_kit is a positive whole number, and the result is the number of complete kits you can pack.
- 2
Use def to name the function and put its parameters inside parentheses. In the indented body, use // for whole-number division. This deliberately counts complete kits rather than fractional kits.
- 3
Use return to send the result back. Outside the function, call it with two values, called arguments, and print the returned value. Defining the function saves its instructions; calling it runs them.
- 4
Trace calls for (23,4), (0,4) and (12,3), substituting each argument into its parameter. Record the result for each call without changing the function definition.
- 5
List invalid inputs such as a zero per_kit or negative supplies. Preserve these as known requirements for the next lesson rather than claiming the present function safely handles them.
See how it works.
Fictional example: a workshop wants complete kits from two inventories.
def complete_kits(supplies, per_kit):
return supplies // per_kit
first = complete_kits(23, 4)
second = complete_kits(12, 3)
print(first, second)The first call uses 23//4=5 because a sixth kit needs 24 supplies. The second uses 12//3=4. The output is 5 4. Each call has its own inputs, so there is no need to overwrite a shared supplies variable. Returning a result also lets another calculation use it; printing inside the function alone would display information without returning this count to the caller.
Did you cover these?
- 23 and 4 return 5.
- Zero supplies returns 0 under the stated contract.
- Zero per_kit is explicitly listed as invalid.
What to finish
A documented function with three call traces and an invalid-input list.
Watch for this
Confusing print with return, or treating fractional kits as complete kits.
How can I tell I understand it?
Predict multiple calls and explain the function contract.
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 tutorial covering if, for, range and function definitions; examples use stable Python 3 syntax.
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.