Python Practice › Loop Programs › Program 55
Number triangle 1, 22, 333
Write a Python program to print row i with the number i repeated i times, for i from 1 to 5, using nested loops.
Output
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
Approach
- An inner loop prints the row number
itimes.
Solution
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
Learn the concept
New to this topic? Read the lesson, then come back.