for loops and range
- Stage
- 1
- Module
- M1.5
- Lessons
- 1
In this module
- Repeat a block of code a fixed number of times with
forandrange(). - Choose the right form of
range()to start counting from a value other than0. - Build a running total across the passes of a loop with an accumulator variable.
- Read a count, then that many more values, entirely inside a loop.
Before this module
Lessons
Practice
Try these on the judges. Each link opens the problem on WMOJ or DMOJ.
- 2022 J2Fergusonball Ratings (opens on WMOJ in a new tab) WMOJ
Rate each of several players from their points and fouls, and count how many earn a top rating.
- 2025 J2Donut Shop (opens on WMOJ in a new tab) WMOJ
Track a donut count through a sequence of baking and selling events.
- 2016 J1Tournament Selection (opens on DMOJ in a new tab) DMOJ
Count wins from a sequence of match results and report which group that count places a team in.
Why DMOJ: Tries the same kind of counting on DMOJ, which holds 2014 to 2020.