Left-Aligned 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 left-aligned descending number triangle in Python. Every row starts from the same number (rows) and counts down, but each next row stops earlier: 54321, 5432, 543, 54, 5.

This is a good pattern to practice nested loops where the inner loop always begins from the same value.

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
54321
5432
543
54
5
1

Complete Python Program

The outer loop controls where each row stops. The inner loop always counts down from rows.

Python
rows = 5

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

🧠 How It Works

1

Choose the maximum number

rows = 5 sets the starting number for every row.

Setup
2

Outer loop (controls row shortening)

for i in range(0, rows) controls how many values are removed from the right end as rows progress. As i grows, the inner loop stops sooner.

Row control
3

Inner loop (count down from rows)

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

Number printing
4

New line

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

Line break
=

Left-aligned 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 maximum number at runtime using input():

Python
rows = int(input("Enter the number of rows: "))

for i in range(0, rows):
    for j in range(rows, i, -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=" ")
  • For a right-aligned look in the console, pad shorter rows with leading spaces before the digits
  • Print the same shape using strings (build each row and print once)
  • Swap the direction to create 12345, 1234... (Program 1)

Avoid

  • Forgetting print() between rows
  • Using the wrong stop value in range() (remember it’s exclusive)
  • Mixing up row control and number printing logic
  • Assuming user input is always valid (wrap int() conversion if needed)

Key Takeaways

1

The inner loop always starts from rows, which keeps the same first digit every row.

2

The outer loop changes the inner loop’s stop condition, making each row shorter.

3

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

4

This pattern is a practical way to learn range(start, stop, step) with a negative step.

❓ Frequently Asked Questions

Because the inner loop always starts from rows. Only the number of printed digits changes each row.
Program 3 prints 54321, then starts the next row from 4 (4321). Program 4 always starts from 5 and shortens by changing the stopping point (5432, 543, ...).
Yes. Use print(j, end=" "). For neat formatting, build a list of numbers and join them with spaces.
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?

Changing only the stop condition of a loop (while keeping the start fixed) is a neat way to generate shrinking patterns like this one.

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