5

Lesson 5 of 20 ยท Repeating

Repeating โ€” Part 13

Do the same step more than once. This is part 13 of 20.

What you'll learn

You will learn how loops repeat code multiple times and how range() controls how many times.

Steps

  1. 1Look at the 'for' line. It says: repeat the indented code a certain number of times. range(${Math.min(3 + Math.floor(n / 2), 8)}) means ${Math.min(3 + Math.floor(n / 2), 8)} times.
  2. 2The indented line (print) runs once for each number in range(). So it would print Step 1, Step 2, Step 3... up to Step ${Math.min(3 + Math.floor(n / 2), 8)}.
  3. 3Without a loop, you'd need to write ${Math.min(3 + Math.floor(n / 2), 8)} separate print() lines! Loops save you from repeating yourself.
  4. 4The 'i' variable counts which round we're on (starting from 0). That's why we write i + 1 to show Step 1 instead of Step 0.

Key Terms

Loop
A way to repeat the same steps multiple times without writing them again and again.
range()
Gives you a sequence of numbers (e.g. 0, 1, 2) so the loop knows how many times to run.
Repeat
To do the same thing more than once. Loops help us repeat.
Python 3
Output
Loading Python... This may take a few seconds.

Your code runs only in your browser. No code is sent to any server. Stay safe and have fun learning!

๐Ÿ–จ๏ธ

Checkout complete lesson on Repeating for Kindergarten

Get the full Repeating track as a printable PDF โ€” all lessons, worksheets, and answer keys.

View in Shop

Your Cart (0)

Your cart is empty

Browse our shop to find activities your kids will love