Beginner ยท ages 8+ ยท while loop ยท variables
Countdown in Python.
Count down from 10 and finish with a message.
The program
Press Run to see what it prints. Change anything you like, then run it again.
count = 10
while count > 0:
print(count)
count = count - 1
print("Blast off!")10 9 8 7 6 5 4 3 2 1 Blast off!
How it works
- A while loop keeps repeating as long as its condition is true.
count = count - 1makes the number smaller each time, so the loop ends. If you forget this line the loop never stops.- Compare it with a
forloop: useforwhen you know how many times, andwhilewhen you do not.
Try this
- Count down from 20 in steps of 2.
- Print only the even numbers.
- Make it count up instead.
Stuck on an error? Read how to debug Python.
Similar ideas
More programs
Hello world and variables
Print a message, store things in variables and join them together.
Beginner ยท ages 8+The Collatz sequence
Start with any number. If it is even, halve it; if odd, triple it and add 1. See how long it takes to reach 1.
Easy ยท ages 11+Decimal to binary
Turn a number into binary by repeatedly dividing by 2.
Easy ยท ages 11+FAQ
Countdown: questions
What does the countdown program do?
Count down from 10 and finish with a message. It prints: 10 / 9 / 8 โฆ
Which Python ideas does it use?
while loop, variables. Beginner level, suitable from about age 8.
How do I run it?
Press Run on this page. To run it on your own computer, install Python 3 and save the code in a file ending in .py. It prints the same thing.
What should I try next?
Count down from 20 in steps of 2. Print only the even numbers. Make it count up instead.
Start a conversation
Want a teacher to guide the learning?
Tell us the learner's age and what they can already do, and we will suggest a starting point. A parent or guardian can make the enquiry.
- Tell us the learnerโs age or grade and goals
- Weโll suggest a suitable class or learning path
- Weโll confirm format, timing and fees with a parent or guardian
Play it, don't just read it
Write some code right now
Free games that need no sign-up. Pick one and play for five minutes.
Pick a game
- Predict the OutputRead a short Python program and choose what it prints. Then watch it runโฆPlay
- Bug HunterA Python program prints the wrong answer. Find the one line with theโฆPlay
- Code BuilderThe lines of a Python program are mixed up. Tap them into the rightโฆPlay
- Code JungleWrite real Python to guide Miko the monkey to every banana. 24 levels:โฆPlay