×

python · level 1 · unit 5 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A does the same job again and again.

Imagine skipping with a rope. You do not write down every single jump. You say "jump 10 times" and off you go. A loop is the same idea: you write the lines once, and Python repeats them for you.

means "do this 3 times". Each time round, lap holds a new number from range: 0, then 1, then 2. Careful: range starts at 0 and stops before the number you give. range(2, 6) counts 2, 3, 4, 5.

The colon and the indented lines matter. Every indented line under the for line is inside the loop and repeats. The first line that is not indented runs once, after the loop has finished.

for lap in range(3):
    print("Lap", lap)
print("Finished!")

Python counts from 0, so 3 laps are numbered 0, 1 and 2.