Increasing Number Triangle (Starts from 0) in Python

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

What You’ll Learn

How to print an increasing number triangle in Python that starts at 0. Each row prints one more number than the previous row, and values increase sequentially across the row.

This pattern is an excellent exercise to understand how outer loops build rows while inner loops control columns and printing.

⭐ Pattern Output

For rows = 6, the pattern looks like this:

Output
0
1 2
2 3 4
3 4 5 6
4 5 6 7 8
5 6 7 8 9 10
1

Complete Python Program

The inner loop starts at 0 so that the first printed value becomes 0. The formula i + j - 1 generates the consecutive values on each row.

Python
rows = 6

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

🧠 How It Works

1

Set the row count

rows = 6 sets the height of the triangle.

Setup
2

Outer loop (rows)

for i in range(1, rows + 1) runs one time per row, increasing the row length each time.

Row control
3

Inner loop (columns)

for j in range(0, i) prints exactly i values on row i.

Number printing
4

Compute the value (start from 0)

i + j - 1 becomes 0 when i = 1 and j = 0, then increases by 1 as j increases.

Formula
=

Triangle that starts at 0

Total values printed: 1+2+…+n = n(n+1)/2, so the time complexity is O(n²) for n rows.

2

Variation — User Input Version

Let the user enter the number of rows using input():

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

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

💡 Tips for Enhancement

Try These

  • Validate input (reject rows < 1) before printing
  • Start from 1 by changing the formula to i + j
  • Remove the trailing space by collecting row values and joining
  • Right-align the triangle using leading spaces
  • Transform it into an alphabet pattern using chr()

Avoid

  • Forgetting print() after each row
  • Using invalid row counts without handling errors
  • Mixing row and column logic in one loop
  • Assuming user input is always numeric (wrap int() if needed)

Key Takeaways

1

The outer loop controls the number of rows.

2

The inner loop prints i values on row i.

3

Using j starting at 0 makes the first row begin with 0.

4

Total printed values follow n(n+1)/2, giving O(n²) time.

❓ Frequently Asked Questions

Because j starts at 0 and the formula i + j - 1 becomes 0 when i = 1.
It prints 1+2+…+n = n(n+1)/2 values in total.
Change i + j - 1 to i + j (or start j from 1).
O(n²), because the total amount printed grows like 1+2+…+n.

Explore More Python Number Patterns!

From pyramids to Floyd’s triangle and beyond—practice nested loops with progressively richer patterns.

All Number Patterns →
Did you know?

Starting the inner loop at 0 is a common trick to shift a pattern down by one, which is why this triangle begins at 0 instead of 1.

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