Increasing Number Triangle Pattern in Python

Beginner
⏱️ 7 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Decreasing Step

What You’ll Learn

How to print an increasing number triangle in Python where the values don’t simply count up by 1 across a row. Instead, each row uses a decreasing step to generate the sequence.

This is a useful pattern for practicing nested loops and carefully updating variables inside the inner 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

We start each row at i, then keep adding a step k that decreases after each printed value.

Python
rows = 5

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

🧠 How It Works

1

Choose the row count

rows = 5 controls how many lines will be printed.

Setup
2

Outer loop starts each row

Row i prints exactly i numbers and begins with the value i.

Row control
3

Step starts high and decreases

k = rows - 1 starts the step at 4 (for 5 rows) and decreases after each printed value.

Step
4

Update res to generate the row

We keep a running value res. After printing the first number, we repeatedly do res += k, print it, then decrement k.

Inner loop
=

Custom increments

Total numbers printed are 1+2+…+r, so runtime is O(r²) for r rows.

2

Variation — User Input Version

Let the user choose the number of rows at runtime and print the same pattern.

Python
rows = int(input("Enter number of rows: "))
if rows < 1:
    raise ValueError("rows must be at least 1")

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

💡 Tips for Enhancement

Try These

  • Remove trailing spaces by building a list for each row and joining it
  • Change the starting step to create different sequences
  • Print the pattern without spaces for a compact look
  • Store the triangle in a 2D list if you want to reuse values
  • Try reversing each row to see a new pattern

Avoid

  • Forgetting to reset k and res for each row
  • Using rows < 1 without validation
  • Decrementing k in the wrong place (sequence will change)
  • Confusing the number of prints per row (should be exactly i)

Key Takeaways

1

Row i prints exactly i numbers and starts with i.

2

A decreasing step k determines how much the next value jumps.

3

Resetting k and res for each row is essential.

4

Total prints are triangular, so runtime is O(r²).

❓ Frequently Asked Questions

We initialize res = i and print j first when j == i, so every row begins with its row number.
k is the step added to res to generate the next number in the row. It decreases each time, changing the jump size.
Exactly i numbers, because the inner loop runs from i to 2i-1.
O(r²), since total prints are 1+2+…+r.

Explore More Python Number Patterns!

Patterns like this sharpen your ability to track variables and steps inside nested loops.

All Number Patterns →
Did you know?

This pattern is a nice example of generating sequences with a changing step size, similar to how some arithmetic series problems are built.

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.

7 people found this page helpful