Solution: Countdown
Explore how to create a countdown program in Python using a for loop. This lesson helps you understand the use of range for counting backward and executing code after a loop, building foundational skills in automation and control flow.
We'll cover the following...
We'll cover the following...
This program counts backward from 5 to 1 and then prints “Liftoff!” — just like a rocket countdown!
range(5, 0, -1)means:Start at 5
Stop before 0
Count down by 1 each time (because of the
-1step).
The
forloop prints each number — 5, 4, 3, 2, 1 — one at a time.After the loop finishes,
print("Liftoff!")runs once to display the final message.