Sequential Number Triangle (Starts from 11) in Python

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

What You’ll Learn

How to print a sequential number triangle in Python where the first value starts at 11. Each row prints one more number than the previous row.

You’ll practice the classic idea that the outer loop controls rows and the inner loop controls columns and printing.

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
11
12 13
13 14 15
14 15 16 17
15 16 17 18 19
1

Complete Python Program

The outer loop builds each row, and the inner loop prints one more value per row. A small formula ensures the first printed number becomes 11.

Python
rows = 5

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

🧠 How It Works

1

Set the number of rows

rows = 5 decides the height of the triangle.

Setup
2

Outer loop (rows)

for i in range(1, rows + 1) runs once per row, growing the row length from 1 up to rows.

Row control
3

Inner loop (columns)

for j in range(1, i + 1) prints i numbers on row i.

Number printing
4

Compute the value

9 + i + j ensures the first value becomes 11 when i = 1 and j = 1, then values increase naturally as j grows.

Formula
=

Sequential number triangle

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

2

Variation — User Input Version

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

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

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

💡 Tips for Enhancement

Try These

  • Validate input (reject rows < 1) before printing
  • Change the start by editing the constant in 9 + i + j
  • Print without the trailing space by building a row list and joining
  • Right-align the triangle by printing leading spaces before each row
  • Replace numbers with characters to create alphabet patterns

Avoid

  • Forgetting print() after each row
  • Using rows as 0 or negative without validation
  • Mixing row and column responsibilities (keep the outer loop for rows)
  • Assuming user input is always valid (wrap int() conversion if needed)

Key Takeaways

1

The outer loop controls how many rows are printed.

2

The inner loop controls how many numbers appear on each row (1..i).

3

The expression 9 + i + j makes the first value start at 11 and keeps the row values increasing.

4

The total prints follow a triangular number: n(n+1)/2, giving O(n²) time.

❓ Frequently Asked Questions

Because when i = 1 and j = 1, the formula 9 + i + j becomes 11.
For rows = n, the program prints 1+2+…+n = n(n+1)/2 numbers overall.
If you want to start from start, use (start - 2) + i + j instead of 9 + i + j.
O(n²) for n rows, since the total amount printed grows quadratically.

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?

Row-by-row triangle patterns are a great way to master nested loops. The total number of values printed after n rows is a triangular number: n(n+1)/2.

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