Reverse Repeated Number Triangle in Python

Beginner
⏱️ 5 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

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:

Output
55555
4444
333
22
1
1

Complete Python Program

The outer loop decreases the digit (and the row length). The inner loop repeats that digit the same number of times.

Python
rows = 5

for i in range(rows, 0, -1):
    for _ in range(i):
        print(i, end="")
    print()

🧠 How It Works

1

Choose the row count

rows = 5 sets the starting digit and the maximum repeat count.

Setup
2

Outer loop (descending digits)

for i in range(rows, 0, -1) selects the digit for each row: 5, 4, 3, 2, 1.

Row control
3

Inner loop (repeat i times)

for _ in range(i) prints the digit i exactly i times using print(i, end="").

Repetition
4

New line

print() moves to the next row.

Line break
=

Reverse repeated triangle

Total digits printed are 1+2+…+n = n(n+1)/2, so time complexity is O(n²) for n rows.

2

Variation — User Input Version

Let the user decide the number of rows at runtime using input():

Python
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

1

The outer loop decreases the digit from rows down to 1.

2

The inner loop repeats the digit exactly i times.

3

Total printed digits follow the triangular number count: n(n+1)/2.

4

This is the reverse of the repeated-number triangle (Program 9).

❓ Frequently Asked Questions

Because the inner loop repeats i times and i decreases each row: 5, 4, 3, 2, 1.
Loop i upward from 1 to rows and repeat it i times (Program 9).
Yes. Use print(i, end=" "). If you want clean alignment, consider fixed-width formatting.
O(n²) for n rows: total prints are 1+2+…+n = n(n+1)/2.

Explore More Python Number Patterns!

Keep going to discover more number pattern programs and strengthen your loop skills.

All Number Patterns →
Did you know?

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²).

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful