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

Make a decision with a condition

About 29 minutes · 7 reading + 22 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

Supply counts can exceed the amount available. A useful program must say what happens in that case instead of silently reporting a misleading plan. Conditions let one set of instructions handle several situations. You will write a rule for fictional kits and test values below, exactly at, and above its threshold.

The idea

A condition chooses a branch; equality belongs to whichever branch you specify.

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

    Write the rule in ordinary language: pack only when available supplies are at least the requested amount. State that equality is acceptable, because having exactly enough supplies still permits packing.

  2. 2

    Compute needed as kits multiplied by per_kit. Compare supplies with needed using >=. Read this symbol aloud as greater than or equal to, and distinguish comparison from assignment with =.

  3. 3

    Copy the if and else structure in the example. Indent each branch by four spaces. Only the branch chosen by the condition runs for that input.

  4. 4

    Make a three-row test table with supplies of 11, 12 and 13, keeping needed at 12. Predict both the message and remainder before an optional run.

  5. 5

    Add a written input rule that kit quantities must be nonnegative whole numbers. This lesson does not validate every possible type; save that limitation alongside the branch tests for later refinement.

Example

See how it works.

Fictional example: four kits need three pencils each. This program protects the packing decision:

python
supplies = 12
kits = 4
per_kit = 3
needed = kits * per_kit
if supplies >= needed:
    print("Pack", kits, "kits")
else:
    print("Need", needed - supplies, "more")

At 12 supplies it prints Pack 4 kits; equality is included. With supplies=11 it prints Need 1 more. With supplies=13 it still packs four kits, leaving one supply unused. The condition does not increase the requested number of kits automatically. Requirements decide the intended behavior, while the comparison implements that requirement.

Check your work

Did you cover these?

  • 11 produces a shortage of 1.
  • 12 follows the packing branch.
  • Both branch bodies are indented consistently.
Your work

What to finish

A conditional program and a three-row threshold test table.

Common mistake

Watch for this

Using > when the requirement includes exactly enough.

How can I tell I understand it?

Predict both branches and justify the equality case.

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.

1A room allows at most 8 kits. Which condition accepts 8?
2needed=15 and supplies=9. What should the shortage branch report?
3A rule accepts nonnegative kit counts up to and including 6. Which pair checks the last accepted count and the first rejected count?
0 of 3 answeredApply the lesson to a short question, then review the explanation.
2
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 — More Control Flow Tools
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.

No sign-in needed.