8

Lesson 8 of 20 ยท Repeating Steps

Repeating Steps โ€” Part 16

Repeat the same step 2, 3, or 4 times. This is part 16 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 Steps for 1st Grade

Get the full Repeating Steps 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