272. Python Program to Print a Row-Number Triangle
EasyPhase 1 · Warm-up
A for loop, str() and * to repeat text are enough here. You have used all three.
Overview
In this pattern, each row repeats its own row number. It trains you to see the link between the row number and what goes in the row.
Problem Statement
Kofi makes a poster for a nursery class. Each number is shown as many times as its value. Read a whole number n and print n rows. Row 1 is 1, row 2 is 22, row 3 is 333, and so on, with no spaces between the digits.
Steps
- Read
nand turn it into a whole number. - Loop over the numbers from 1 to
n. - Turn the number into text.
- Print that text, repeated as many times as the number.
Examples
Example 1. Input 4 gives:
1
22
333
4444
Why: row 4 shows the digit 4, four times.
Example 2. Input 2 gives:
1
22
Why: there are 2 rows. Row 1 has one 1, and row 2 has two 2s.
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. Line i holds the digit i, written i times, with no spaces. 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.