Rullst AcademyRullst Academy/Lesson
Python: from first line to project · Lesson 06 / 12

Repeat with a clear path

Adding ten, twenty and fifteen minutes by hand works. A loop repeats the same rule when the list changes.

Learning paths10 min

Let's discover together

  1. 1

    for minutes in durations visits one value at a time, in list order. The indented block repeats for each value.

  2. 2

    Start total = 0 before the loop. total = total + minutes accumulates: first 10, then 30, then 45. Resetting total inside the loop would lose earlier values.

  3. 3

    range(1, 4) produces 1, 2 and 3: end value 4 is excluded. Their sum is 6. Do not confuse the written limit with the last visited value.

  4. 4

    An empty list does not execute the for body; total remains 0. Testing emptiness helps find programs that work only with populated examples.

✦
YOUR MISSION

Traverse a list, accumulate a total and interpret the exclusive end of range.

Now it's your turn

Discovery workshop

Read, predict, check

Compare the two versions. Show result reveals a prepared output: this panel does not run Python. Then practise with the activity file.
Mini experiment

Learning simulation: compare cards and check your predictions. The browser is not compiling Rust or starting a server.

durations = [10, 20, 15]
total = 0
for minutes in durations:
    total = total + minutes
print(total)
Build your answers and check when you are ready.
A moment to understand

Where should the total start when summing the whole list?

I need a hint

The accumulator must remember earlier steps.

Loading your journey…

Take it with you

Run the sum with three durations, then an empty list. Make a table showing total before and after each iteration.

PYTHON · .py

Your Python workbench

Here you read and predict prepared outputs. To run the actual code, download the activity file, edit it on your computer and use Python. Rullst Academy grades lesson answers; it does not verify local execution.

Save and run

Extract the activity ZIP into its own folder. Open a terminal there and use your system’s command. If downloading your edited file separately, use its actual name in the command. Save before running again.

Windows
python lesson.py
macOS / Ubuntu
python3 lesson.py
My files and GitHub

The editor keeps a local draft and can send a .py file to GitHub with your confirmation. Download your edited code to preserve it. The ZIP is starter material; for the final project, also publish data and test files following PUBLISH.md.

At your own pace

My files and GitHub

Every lesson can become your own record: code, notes or a practice plan. Saving a file to GitHub is optional and does not change your XP.

Student guide

The editor and downloads open when this lesson is available to your account. Check access below or return to the track map.

Checking your access to this lesson…

Rullstpetbot

AI can make mistakes. Check the lesson material.