Descending Repeated Number Triangle in Python

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:
5
44
333
2222
11111Complete Python Program
The outer loop counts down the digit. The inner loop repeats it more times on each next row.
rows = 5
for i in range(rows, 0, -1):
repeat = rows - i + 1
for _ in range(repeat):
print(i, end="")
print()🧠 How It Works
Choose the row count
rows = 5 sets the starting digit and the total number of rows.
Outer loop (digit decreases)
for i in range(rows, 0, -1) picks the digit: 5, then 4, then 3, down to 1.
Repeat count increases
repeat = rows - i + 1 becomes 1, 2, 3, 4, 5 as i decreases.
Inner loop prints i repeatedly
for _ in range(repeat) prints i exactly repeat times using print(i, end="").
Descending 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):
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
The outer loop decreases the digit from rows down to 1.
The repeat count increases using rows - i + 1.
Total printed digits follow the triangular number count: n(n+1)/2.
This pattern combines a descending digit with an increasing row length.
❓ Frequently Asked Questions
i, but the repeat count rows - i + 1 grows by 1 each time.i.Explore More Python Number Patterns!
Keep going to discover more number pattern programs and strengthen your loop skills.
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²).
12 people found this page helpful
