Sequential Number Triangle (Starts from 11) in Python

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:
11
12 13
13 14 15
14 15 16 17
15 16 17 18 19Complete 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.
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
Set the number of rows
rows = 5 decides the height of the triangle.
Outer loop (rows)
for i in range(1, rows + 1) runs once per row, growing the row length from 1 up to rows.
Inner loop (columns)
for j in range(1, i + 1) prints i numbers on row i.
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.
Sequential number triangle
Total numbers printed are 1+2+…+n = n(n+1)/2, so time complexity is O(n²) for n rows.
Variation — User Input Version
Let the user enter the number of rows at runtime using input():
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
rowsas 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
The outer loop controls how many rows are printed.
The inner loop controls how many numbers appear on each row (1..i).
The expression 9 + i + j makes the first value start at 11 and keeps the row values increasing.
The total prints follow a triangular number: n(n+1)/2, giving O(n²) time.
❓ Frequently Asked Questions
i = 1 and j = 1, the formula 9 + i + j becomes 11.rows = n, the program prints 1+2+…+n = n(n+1)/2 numbers overall.start, use (start - 2) + i + j instead of 9 + i + j.Explore More Python Number Patterns!
From pyramids to Floyd’s triangle and beyond—practice nested loops with progressively richer patterns.
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.
12 people found this page helpful
