Python loops for beginners
Repeat work with for and while loops, counters, running totals, and loop control.
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) # 12Initialize 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.
- Count down with while — The while statement
- Stop at done — Infinite loops and break
- Skip comment lines — Finishing iterations with continue
- Greet each friend — Definite loops using for
- Count and accumulate — Counting and summing loops
- Largest so far — Maximum and minimum loops
- Smallest so far — Maximum and minimum loops
- 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 →