Increasing Start Pattern Filled with 5 in Python

What You’ll Learn
How to print a fixed-width number pattern in Python where each row starts smaller and ends at 5, filling the remaining positions with 5.
This pattern is a handy exercise for printing two parts per row: an increasing sequence, then a repeated filler value.
⭐ Pattern Output
For rows = 5, the pattern looks like this:
5 5 5 5 5
4 5 5 5 5
3 4 5 5 5
2 3 4 5 5
1 2 3 4 5Complete Python Program
Print from i to rows, then print rows again to fill the remaining columns.
rows = 5
for i in range(rows, 0, -1):
for j in range(i, rows + 1):
print(j, end=" ")
for _ in range(i - 1):
print(rows, end=" ")
print()🧠 How It Works
Set the maximum value
rows = 5 is both the maximum number and the fixed row width.
Outer loop (row start)
for i in range(rows, 0, -1) makes the row start values 5, 4, 3, 2, 1.
First inner loop prints i..rows
for j in range(i, rows + 1) prints the increasing sequence for that row.
Second inner loop fills remaining with rows
for _ in range(i - 1) prints rows enough times so each row has exactly 5 numbers.
Fixed-width filled pattern
Every row has the same width, but the increasing part gets longer as i decreases.
Variation — User Input Version
Let the user choose the maximum value at runtime:
rows = int(input("Enter the maximum number: "))
for i in range(rows, 0, -1):
for j in range(i, rows + 1):
print(j, end=" ")
for _ in range(i - 1):
print(rows, end=" ")
print()💡 Tips for Enhancement
Try These
- Remove trailing spaces by building the row as a list and joining it
- Use a different filler value (e.g., 0) instead of
rows - Print descending sequences instead of increasing ones
- Right-align the output by adding leading spaces
- Convert this logic into a reusable function
Avoid
- Forgetting that the goal is fixed-width rows
- Mixing up which loop prints the sequence vs. the filler
- Assuming user input is always valid
- Changing ranges without re-checking row length
Key Takeaways
Each row prints two parts: an increasing sequence and a filler.
The row width stays fixed at rows columns.
The sequence length grows as the row start decreases.
Nested loops are a natural fit for row/column style output.
❓ Frequently Asked Questions
rows numbers per row (5 in this example)." ".join(...).print(rows, ...) with print(filler, ...) and define filler as needed.Explore More Python Number Patterns!
Keep going to discover more number pattern programs and strengthen your loop skills.
Many patterns can be expressed as โprint a variable-length sequence, then print a filler.โ Thinking in two segments per row makes nested-loop patterns easier to design.
12 people found this page helpful
