Descending Repeated Number Triangle in Python

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

What You’ll Learn

How to print a descending repeated number triangle in Python using nested for loops. Each row prints a digit repeated multiple times while the digit decreases: 5, 44, 333, 2222, 11111.

This is a useful exercise for understanding how the outer loop sets the digit and the inner loop controls repetition count.

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
5
44
333
2222
11111
1

Complete Python Program

The outer loop counts down the digit. The inner loop repeats it more times on each next row.

Python
rows = 5

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

🧠 How It Works

1

Choose the row count

rows = 5 sets the starting digit and the total number of rows.

Setup
2

Outer loop (digit decreases)

for i in range(rows, 0, -1) picks the digit: 5, then 4, then 3, down to 1.

Row control
3

Repeat count increases

repeat = rows - i + 1 becomes 1, 2, 3, 4, 5 as i decreases.

Repetition
4

Inner loop prints i repeatedly

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

Number printing
=

Descending 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):
    repeat = rows - i + 1
    for _ in range(repeat):
        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 instead (Program 9)
  • Right-align the triangle by printing leading spaces before each row
  • Replace numbers with letters to create repeated-letter patterns

Avoid

  • Forgetting print() between rows
  • Mixing up repeat count logic (verify the row lengths)
  • 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 repeat count increases using rows - i + 1.

3

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

4

This pattern combines a descending digit with an increasing row length.

❓ Frequently Asked Questions

Because each next row uses a smaller i, but the repeat count rows - i + 1 grows by 1 each time.
Yes. Change the repeat formula to match the desired row length for each i.
Use an outer loop that counts up and repeat the row number i times (Program 9).
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?

The number of printed digits still forms 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