Reverse Descending Number Triangle in Python

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

What You’ll Learn

How to print a reverse descending number triangle in Python using nested loops. Each row prints a decreasing sequence like 54321, then 4321, then 321, and so on.

This pattern strengthens your understanding of counting backwards with range() and combining it with the row limit from an outer loop.

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
54321
4321
321
21
1
1

Complete Python Program

The outer loop counts down the row length. The inner loop prints numbers from that length down to 1.

Python
rows = 5

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

🧠 How It Works

1

Choose the row count

rows = 5 sets the maximum starting digit for the first row.

Setup
2

Outer loop (row length)

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

Row control
3

Inner loop (count down to 1)

for j in range(i, 0, -1) prints i, i-1, ..., 1 using print(j, end="").

Number printing
4

New line

print() ends the row and moves to the next line.

Line break
=

Reverse descending triangle

Total digits printed: 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 j in range(i, 0, -1):
        print(j, end="")
    print()

💡 Tips for Enhancement

Try These

  • Validate input (reject rows < 1) before printing
  • Add spaces between numbers with print(j, end=" ")
  • Change the row direction to print 1..i instead (Program 1 style)
  • Right-align the triangle by printing leading spaces before each row
  • Print characters instead of numbers to create alphabet patterns

Avoid

  • Forgetting print() between rows
  • Using the wrong step in range() when counting down
  • Mixing up row control and column control (outer loop should define the row)
  • Assuming user input is always valid (wrap int() conversion if needed)

Key Takeaways

1

The outer loop controls the row length by counting down from rows to 1.

2

The inner loop counts down from i to 1 to print each row in reverse.

3

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

4

This is a classic pattern for practicing reverse ranges in Python.

❓ Frequently Asked Questions

Because the outer loop decreases the row limit: 5, 4, 3, 2, 1. Each row prints from that limit down to 1.
Use print(j, end=" "). If you want to avoid trailing spaces, collect the row values and print " ".join(...).
Yes. That’s the descending triangle in Program 1: each row prints 1..i, and i decreases each row.
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?

Reverse ranges like range(n, 0, -1) are a common Python pattern for counting down. Pairing them with nested loops makes many reverse triangles easy to build.

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