CoursePython from Scratch to Intermediate · Module 4: Decisions and Loops · part 28 of 75
Part 28 · Module 4: Decisions and Loops

Lesson 2: for loops, the same steps for every loan

16 min read·14 Oct 2026
Module 4 · Lesson 2 · About 45 minutes · Needs: Module 4 Lesson 1 (if, elif, else), Module 3 Lesson 2 (split and splitlines), Module 2 (int(), +=, min())

The situation

Amira wants an answer for the whole shelf, not one loan: "Which of these twelve loans are overdue, and what is owed?" In Lesson 1 you decided whether one loan was overdue. Ben's loan, L13,B20,Ben,21,, was due on shelf day 35, and today is day 44, so he is 9 days late and owes 180 pence.

Copying that code twelve times would work, with twelve chances for a typing slip. This lesson teaches the for loop: write the steps once, and Python repeats them for every loan.

BY HAND WITH A LOOP L01: split, due, print L02: split, due, print L04: split, due, print L05: split, due, print L07: split, due, print ... 7 more copies steps written once Python repeats them for all 12 loans 12 copies: 12 chances for a slip 3 lines, same answer each time
Copying the steps for each of the twelve loans (red, risky) gives twelve chances for a slip; a loop (blue, your code) writes them once and Python repeats them.

The rest of this part opens with an account

Signing up is free and takes one email. Nothing to pay, and nothing renews.