The dragon explains
Doing something many times
The dragon: You've written the same print() three times before to make three lines. There's a much better way.
The dragon: for i in range(3): repeats the indented lines below it — three times, automatically.
example.pyPython 3for i in range(3): print("Roar!")
OutputRoar! Roar! Roar!The dragon: Change the number, change the count. No copy-pasting needed.
example.pyPython 3for i in range(5): print("Flap!")
OutputFlap! Flap! Flap! Flap! Flap!The dragon: i is the loop's own counter — it changes every single time the loop runs.
example.pyPython 3for i in range(4): print(i)
Output0 1 2 3The dragon: A loop isn't just 'repeat this text' — it's 'run this code, with a different i each time.'
The dragon: Now a corridor full of gems. One lap of the loop: one step, one grab. Watch the same two lines light up again and again.
Quick check
Check your understanding
Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.
Question 1 of 1
for i in range(3): print("Go!") — does i actually change anything here?
question.pyPython 3for i in range(3): print("Go!")
- i changes each time, but this code never uses it, so the output looks the sameCorrect
- No — i only exists if you print it
- This is exactly the same as writing print("Go!") three separate times, with no real difference
Why: i really does become 0, then 1, then 2 — but this code never uses i, so you can't tell from the output. The loop is still doing real work each pass, even when that work happens to look identical.
In the game
What you'll practice
Three levels in the game: one guided first try with the shape of the answer already there, then two to solve on your own.
- 1
GuidedYour first try
Three gems in a row. This loop walks the dragon three steps — but nothing picks the gems up. Add grab() INSIDE the loop (indented, under move_right()), so every lap is a step AND a grab.
- +2
PracticeTwo more, on your own
This lesson is part of PRO.
PRO is a one-time $49.99 purchase, no subscription, and unlocks this whole topic along with everything else. Topics 1–3 are free, start to finish.
Unlock this lesson with PROStuck three times? The game offers the answer — unasked.