Increasing Integer Pattern in Python

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

What You’ll Learn

How to print the following increasing integer pattern in Python using nested loops and a small step-based update:

  • 1
  • 2 6
  • 3 7 10
  • 4 8 11 13
  • 5 9 12 14 15

This pattern is a great exercise for understanding how values can be generated using a controlled increment inside a loop.

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
1

Complete Python Program

Each row starts by printing i. Then it computes the next values using a decreasing step m and an accumulator k.

Python
for i in range(1, 6):
    print(i, end=" ")
    m = 4
    k = i + m
    for j in range(1, i):
        print(k, end=" ")
        m -= 1
        k = k + m
    print()

🧠 How It Works

1

Outer loop controls the row number

for i in range(1, 6) creates 5 rows and prints i as the first value in each row.

Row control
2

Initialize step and next value

m = 4 (which is rows - 1) and k = i + m sets the next number to print after i.

Setup
3

Inner loop prints remaining values

for j in range(1, i) runs i - 1 times. Each time it prints k, then decreases m and updates k = k + m.

Value generation
4

New line after each row

print() moves to the next line for the next row.

Line break
=

Increasing integer pattern

Total printed numbers are 1+2+…+n = n(n+1)/2, so this runs in O(n²) time for \(n\) rows.

2

Variation — User Input Version

Print the same pattern for any number of rows by using rows - 1 as the initial step size.

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

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

💡 Tips for Enhancement

Try These

  • Validate input (reject rows < 1) before printing
  • Remove trailing spaces by building a row list then " ".join(...)
  • Change the starting step (rows - 1) to experiment with different growth
  • Right-align the rows for a different visual effect
  • Print the pattern using formatted columns for better readability

Avoid

  • Forgetting to decrease m (the row values won’t match the pattern)
  • Resetting m inside the inner loop (it must shrink each print)
  • Assuming user input is always valid (wrap int() conversion if needed)
  • Mixing spacing rules without updating the output section

Key Takeaways

1

Each row begins with i, then generates additional values using k and a shrinking step m.

2

m starts at rows - 1 and decreases after each printed value in the row.

3

The inner loop runs i - 1 times, so total prints are \(n(n+1)/2\).

4

This pattern reinforces how loop state (like m) can shape generated sequences.

❓ Frequently Asked Questions

For 5 rows, m starts at 4. That initial step creates the correct jump to the next value in the row, then the step shrinks each time to match the pattern.
Then k will increase by a constant amount and the row values will not match the intended sequence.
Yes. Instead of printing immediately, append values to a list and print " ".join(map(str, row)) at the end of each row.
O(n²) for n rows, because the program prints 1+2+…+n values.

Explore More Python Number Patterns!

Practice nested loops and sequence generation with progressively richer number patterns.

All Number Patterns →
Did you know?

This pattern is a good example of using a shrinking step size (4, 3, 2, 1, ...) to generate non-linear sequences inside loops—useful in many grid and diagonal traversal problems.

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