Step by Step
The portal opens to a long, winding staircase floating in the void. Hoppy needs to climb it.
Loops don't just repeat blindly. They know where they are. They keep count.
The Counter
In for i in range(5):, the variable i is a loop variable. It changes every time the loop runs.
for i in range(3):
print("Now i is:")
print(i)
This will print 0, then 1, then 2.
Your Mission
1
The Climb
Write a for loop that runs 5 times using range(5).
2
Count Steps
Inside the loop, print the variable i.
3
Label It
Also print the text "Step" inside the loop (either before i or on the same line).
Starting from Zero
Programmers count from 0! The first number in range(5) is 0, and the last one is 4.
Suggested SolutionExpandCollapse
ExpandCollapse
Solution:
Keep climbing:
for i in range(5):
print("Step", i)Advanced TipsWant more? Click to expandClick to collapse
You don't have to name it i. You can call it step, number, or banana.
for step in range(5): works exactly the same way, but it's easier to read!
Loading...
Terminal
Terminal
Ready to run...