281. Python Program to Print a Countdown Number Triangle
EasyPhase 1 · Warm-up
You have everything for this one: nested for loops and a range() that counts down.
Overview
This pattern counts down inside each row, and the rows get shorter. It trains you to make range() count backwards and stop at the right place.
Problem Statement
Jamal makes a countdown sign for a rocket launch in a school play. Read a whole number n and print n rows:
- Every row counts down from
n. - Row 1 goes down to 1, row 2 stops at 2, row 3 stops at 3, and so on.
- The last row is just
n.
There are no spaces between the digits.
Steps
- Read
nand turn it into a whole number. - Loop over the rows. Work out where each row stops: 1, then 2, then 3, up to
n. - In each row, print the numbers from
ndown to the stop number, on one line. - End the line after each row.
Examples
Example 1. Input 5 gives:
54321
5432
543
54
5
Why: every row starts at 5. Each row stops one number earlier than the row above it.
Example 2. Input 3 gives:
321
32
3
Why: 3 rows, all starting at 3. The last row is just 3.
Input
One whole number n, from 1 to 9. Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Output
n lines of digits, with no spaces between them. Every line starts at the left edge, with no space in front. The tests try 5 different inputs.
Try it first. The solution opens when you solve this question, or after 3 tries with Submit.