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

Repeat work across a list

About 32 minutes · 7 reading + 25 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

Small datasets often contain one quantity per event, shift or batch. Rewriting the same calculation for each value is fragile, and adding a fourth record should not require inventing new variable names. A list stores related values together. A loop visits them in order while a running total preserves work already completed.

The idea

An accumulator is a variable that keeps a running result. Each pass through the loop, called an iteration, updates that result.

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

    Create the fictional list [3, 5, 2], where each item is the number of kits requested for one workshop session. Write the unit beside the list so a total cannot be mistaken for pencils.

  2. 2

    Initialize total to zero before the loop. Inside the loop, add the current count to the previous total. Explain why resetting total inside the loop would discard earlier sessions.

  3. 3

    Draw columns for iteration, count, total before and total after. Trace all three iterations. Read the final print only after the loop has finished, using its indentation as a guide.

  4. 4

    Add a fourth count of 4 and repeat the trace. Then test an empty list. With no iterations the initialized total remains zero, which is a useful and defined result.

  5. 5

    Save the list, trace and empty-list result. If you run Python, compare actual output with predictions; if you work on paper, use addition independently to check the final sum.

Example

See how it works.

Fictional example: three workshop sessions request three, five and two kits.

python
requests = [3, 5, 2]
total = 0
for count in requests:
    total = total + count
print("Kits requested:", total)

The running totals are 3, then 8, then 10. Python assigns each list item to count in turn. The print statement is outside the indented body, so it produces one summary: Kits requested: 10. With requests=[] the loop body never executes, but total still exists and equals zero. With [3,5,2,4] the fourth update changes total from 10 to 14. No extra calculation line is needed.

Check your work

Did you cover these?

  • Running totals are 3, 8 and 10.
  • Four-item total is 14.
  • Empty input leaves total at zero.
Your work

What to finish

A four-column loop trace covering original, extended and empty lists.

Common mistake

Watch for this

Putting total=0 inside the loop or printing before the final update.

How can I tell I understand it?

Explain why an empty list returns zero and an added item needs no new loop code.

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 loop starts total=0 and adds each value in [2,6,1]. What is the final total?
2A loop sets total=0 inside every iteration before adding count. With [4,7], what final total results?
3A program sets total=0, loops over requests=[] adding each count to total, then prints total after the loop. What happens?
0 of 3 answeredApply the lesson to a short question, then review the explanation.
3
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.

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.