──────────────────────────────────────

13. Game Loops · Count Down to Launch

Use a range to generate a sequence and explain its stopping rule.

Lesson files · lessons/loops-and-games/for-and-range

Before you start
- Use indentation to group instructions under an if.
- Read a whole number with int(input()).

By the end
- Use for and range() to count backward.
- Use indentation to make the launch message run once.
- Predict whether the stop value will appear in the countdown.

Where you can use it
Count down the last few seconds of a game and show a start message when the countdown ends.

A for loop takes one value at a time from a sequence. In range(3, 0, -1), start at 3 and subtract one each time. The loop stops before 0, so the indented print runs for 3, 2 and 1.

The print after the loop runs once when the countdown is over. Start from 0 to try a range with zero steps to print.

Predict
Is 0 printed by the example loop?
- No.
- Yes.

Worked example (example.py)

for number in range(3, 0, -1):
    print(number)
print("Launch!")


Example result
3
2
1
Launch!

Read a starting number. Count down from that number to 1, then print Blast off! on its own line. At 0, launch straight away.

Starter program (starter.py)

start = int(input())
for number in range(3, 0, -1):
    print(number)
print("Launch!")


Starter input
5

Hint
Replace the first value in range with start. Leave the announcement outside the loop.

Case 1. Try the sample
Input
5
Expected output
5
4
3
2
1
Blast off!

Case 2. Short countdown
Input
2
Expected output
2
1
Blast off!

Case 3. Launch now
Input
0
Expected output
Blast off!

Stretch
Count down by twos from 10, and predict the last number.

Reflect
Why does indenting the final print change the announcement?

Check your prediction
No. range stops before its stop value, even when counting backwards.
