Countdown Timer
Beginner · Write the code · from Python While Loops: When For Loops Aren't Enough
From the lesson: Python While Loops: When For Loops Aren't Enough
A vending machine doesn't know how many coins you'll insert. It just keeps waiting: "while the total is less than the price, keep accepting coins." It can't use a for loop because it doesn't know the number of iterations in advance. It needs a while loop.
Read the lessonUse a while loop to print a countdown from 5 to 1, followed by "Blastoff!" on the last line.
Expected output:
5
4
3
2
1
Blastoff!# Create a countdown from 5 to 1, then print "Blastoff!"
More While Loops exercises
- Power of 2 FinderBeginner
- Predict the OutputBeginner
- Fix the Bug: Digit CounterBeginner
- The Collatz SequenceBeginner
All Python exercises · 50 practice problems · Control Flow quiz