BEGINNER PYTHON · CHAPTER 05

Python loops for beginners

Repeat work with for and while loops, counters, running totals, and loop control.

Practice Python loops →Download the chapter notebook

Understanding loops and iterations

Loops let a program repeat a small set of instructions. A for loop visits each item in a sequence, while a while loop continues as long as its condition is true. Practice updating counters and accumulators and deciding when a loop should stop.

total = 0
for number in [2, 4, 6]:
    total = total + number
print(total)  # 12

Initialize the total before the loop so each iteration adds to the result of the previous one.

What you will practice

Work through eight coding missions, then test your understanding with ten multiple-choice questions. Each mission provides starter code, a hint, and feedback after you run it.

  1. Count down with while — The while statement
  2. Stop at done — Infinite loops and break
  3. Skip comment lines — Finishing iterations with continue
  4. Greet each friend — Definite loops using for
  5. Count and accumulate — Counting and summing loops
  6. Largest so far — Maximum and minimum loops
  7. Smallest so far — Maximum and minimum loops
  8. A resilient number loop — Exercises: Exercise 1

Your chapter progress is saved in this browser. Complete all 18 checks to unlock a certificate at your earned practice score, and download your notebook or grade report to keep a copy.

Read, practice, and try again

For the chapter reading, see Python for Everybody: Loops and iterations by Charles R. Severance (CC BY 4.0). ZHUDDLE adds its own practice activities and scoring. The browser runs Python after its first interpreter download; no local installation is required.

Start the loops exercises →