Mina wants a bow just once, but print("bow") is pushed in under range(3).
A pushed-in line is inside the loop, so Bo bows 3 times.
The mix-up to fix: move the bow line back to the edge, so it runs once, after the loop.
Words to know
loop
A way to repeat lines without typing them again.
for
The word that starts a loop.
range
Says how many turns the loop takes.
indent
Pushed in a little, to show a line is inside the loop.
turn
One time round the loop.
Watch out
Range of five counts from zero to four, not from one to five. It is still five numbers.
Spaces matter in Python. A line is inside the loop only when it is pushed in under the for line.
A line pushed in too far repeats too. A bow that should happen once would bow on every turn.
Changing the number in range changes how many turns, and nothing else.
Try it
How many times does Bo wave? for i in range(3): then print("wave") pushed in
Mina changes range(5) to range(8). How many waves now?
A loop of range(4) has wave and spin pushed in, and print("Bow") after it. How many times does Bow run?
Does range of five start counting at zero or one?
True or false: a line pushed in under for runs only once.
Answers: 1. 3 times · 2. 8 waves · 3. Once · 4. Zero · 5. False
Try at homeAsk a grown-up to be the coder and call out a loop, like repeat six times: clap, then spin. You are the computer, so you do exactly that, and then you swap. Spot loops around the house too, like stairs, the chorus of a song or brushing teeth.
For grown-upsBe the computer together: say a loop such as repeat six times, clap and then spin, and your child does exactly that. Then swap, and spot loops at home, like the chorus of a song or stairs.
Open these notes on screenScan the code, or go to tutorpip.com.