Reverse Repeated Number Triangle in Python

What You’ll Learn
How to print a reverse repeated number triangle in Python using nested for loops. Each row repeats the same digit, and the digit decreases while the row length shrinks: 55555, 4444, 333, 22, 1.
This pattern is ideal for practicing a descending outer loop and using the row value as the repeat count.
⭐ Pattern Output
For rows = 5, the pattern looks like this:
55555
4444
333
22
1Complete Python Program
The outer loop decreases the digit (and the row length). The inner loop repeats that digit the same number of times.
rows = 5
for i in range(rows, 0, -1):
for _ in range(i):
print(i, end="")
print()🧠 How It Works
Choose the row count
rows = 5 sets the starting digit and the maximum repeat count.
Outer loop (descending digits)
for i in range(rows, 0, -1) selects the digit for each row: 5, 4, 3, 2, 1.
Inner loop (repeat i times)
for _ in range(i) prints the digit i exactly i times using print(i, end="").
New line
print() moves to the next row.
Reverse repeated triangle
Total digits printed are 1+2+…+n = n(n+1)/2, so time complexity is O(n²) for n rows.
Variation — User Input Version
Let the user decide the number of rows at runtime using input():
rows = int(input("Enter the number of rows: "))
for i in range(rows, 0, -1):
for _ in range(i):
print(i, end="")
print()💡 Tips for Enhancement
Try These
- Validate input (reject
rows < 1) before printing the pattern - Add spaces between digits with
print(i, end=" ") - Print the ascending repeated triangle (Program 9) by looping upward
- Change output to a right-aligned triangle by printing leading spaces per row
- Replace digits with characters to build similar repeated-letter patterns
Avoid
- Forgetting
print()between rows - Mixing up the outer/inner loop roles
- Using negative or zero rows without validation
- Assuming user input is always valid (wrap
int()conversion if needed)
Key Takeaways
The outer loop decreases the digit from rows down to 1.
The inner loop repeats the digit exactly i times.
Total printed digits follow the triangular number count: n(n+1)/2.
This is the reverse of the repeated-number triangle (Program 9).
❓ Frequently Asked Questions
i times and i decreases each row: 5, 4, 3, 2, 1.i upward from 1 to rows and repeat it i times (Program 9).print(i, end=" "). If you want clean alignment, consider fixed-width formatting.Explore More Python Number Patterns!
Keep going to discover more number pattern programs and strengthen your loop skills.
Just like many triangle patterns, the total printed digits here form a triangular number: 1+2+…+n = n(n+1)/2. That’s why the output size grows like O(n²).
12 people found this page helpful
