Increasing Start Pattern Filled with 5 in Python

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

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:

Output
5 5 5 5 5
4 5 5 5 5
3 4 5 5 5
2 3 4 5 5
1 2 3 4 5
1

Complete Python Program

Print from i to rows, then print rows again to fill the remaining columns.

Python
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

1

Set the maximum value

rows = 5 is both the maximum number and the fixed row width.

Setup
2

Outer loop (row start)

for i in range(rows, 0, -1) makes the row start values 5, 4, 3, 2, 1.

Row control
3

First inner loop prints i..rows

for j in range(i, rows + 1) prints the increasing sequence for that row.

Sequence
4

Second inner loop fills remaining with rows

for _ in range(i - 1) prints rows enough times so each row has exactly 5 numbers.

Fill
=

Fixed-width filled pattern

Every row has the same width, but the increasing part gets longer as i decreases.

2

Variation — User Input Version

Let the user choose the maximum value at runtime:

Python
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

1

Each row prints two parts: an increasing sequence and a filler.

2

The row width stays fixed at rows columns.

3

The sequence length grows as the row start decreases.

4

Nested loops are a natural fit for row/column style output.

❓ Frequently Asked Questions

Exactly rows numbers per row (5 in this example).
Yes. Collect values in a list and print " ".join(...).
Replace print(rows, ...) with print(filler, ...) and define filler as needed.
O(n²) for n rows since it prints \(n\) values per row.

Explore More Python Number Patterns!

Keep going to discover more number pattern programs and strengthen your loop skills.

All Number Patterns →
Did you know?

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.

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