273. Python Program to Print an Upside-Down Star Triangle
EasyPhase 1 · Warm-up
One for loop with a range() that counts down does the job. You have seen both.
Overview
This is the star triangle turned upside down. It shows you how to make a loop count down instead of up.
Problem Statement
Lucía makes a pennant for a football team's web page. A pennant is a flag in the shape of a triangle. Read a whole number n and print n rows of stars: n stars in the first row, then one star less in each row, down to 1 star. The stars touch: there are no spaces between them. Every row starts at the left edge.
Steps
- Read
nand turn it into a whole number. - Loop over the numbers from
ndown to 1. - In each turn, print that many stars.
Examples
Example 1. Input 4 gives:
****
***
**
*
Why: the first row has 4 stars. Each row has one star less, and the last row has 1.
Example 2. Input 2 gives:
**
*
Why: 2 rows, with 2 stars and then 1 star.
Input
One whole number n (1 or more). 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 stars, from n stars down to 1 star. The tests try 5 different inputs.
Try it first. The solution opens when you solve this question, or after 3 tries with Submit.