Python Practice › Loop Programs › Program 55

Number triangle 1, 22, 333

EasyLoop Programs · 55 of 90

Write a Python program to print row i with the number i repeated i times, for i from 1 to 5, using nested loops.

Advertisement
Output
1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 

Approach

  1. An inner loop prints the row number i times.

Solution

Python
for i in range(1, 6):    for _ in range(i):        print(i, end=" ")    print()
Output
1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More loop programs

← All 90 Loop Programs