Increasing Number Triangle Pattern in Python

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:
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15Complete Python Program
We start each row at i, then keep adding a step k that decreases after each printed value.
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
Choose the row count
rows = 5 controls how many lines will be printed.
Outer loop starts each row
Row i prints exactly i numbers and begins with the value i.
Step starts high and decreases
k = rows - 1 starts the step at 4 (for 5 rows) and decreases after each printed value.
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.
Custom increments
Total numbers printed are 1+2+…+r, so runtime is O(r²) for r rows.
Variation — User Input Version
Let the user choose the number of rows at runtime and print the same pattern.
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
kandresfor each row - Using
rows < 1without validation - Decrementing
kin the wrong place (sequence will change) - Confusing the number of prints per row (should be exactly
i)
Key Takeaways
Row i prints exactly i numbers and starts with i.
A decreasing step k determines how much the next value jumps.
Resetting k and res for each row is essential.
Total prints are triangular, so runtime is O(r²).
❓ Frequently Asked Questions
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.i numbers, because the inner loop runs from i to 2i-1.Explore More Python Number Patterns!
Patterns like this sharpen your ability to track variables and steps inside nested loops.
This pattern is a nice example of generating sequences with a changing step size, similar to how some arithmetic series problems are built.
7 people found this page helpful
