An increasing number triangle from 11 prints i values on row i, each computed as 9 + i + j — so the first cell is always 11.
Remember
Rule: for i from 1 to rows
for j from 1 to i
print (9 + i + j) and a space
11
12 13
13 14 15
14 15 16 17
15 16 17 18 19 ← rows = 5
Follows the number-star diamond in Program 31; next is the same shape starting from 1 in Program 33.
Approach
How to Solve It
Outer loop grows i. Inner loop prints i values with the formula 9 + i + j, separated by spaces.
Method
Idea
Best for
Formula 9 + i + j
Base offset 9 shifts the triangle to start at 11
Learning, interviews
Custom base
base_val + i + j with input()
Flexible starting number
Compact rows = 3
Same structure; easier to trace by hand
Paper walkthrough
Pseudocode
Pseudocode
for i from 1 to rows:
for j from 1 to i:
print (9 + i + j) and a space
print newline
Cheat sheet
Goal
Pattern
Grow each row
for i in range(1, rows + 1):
Print i values
for j in range(1, i + 1):
Start at 11
print(9 + i + j, end=" ")
Custom base
print(base_val + i + j, end=" ")
End of row
print()
Printing Numbers vs Starting a New Line
API
Effect
Use for
print(value, end=" ")
Stays on the same line
Each number
print()
Ends the current line
After the inner loop
Print each value with a trailing space, then break once with print(). Putting print() inside the inner loop prints one number per line.
Try it
Live Preview
Change the row count and the increasing triangle updates instantly.
Whole numbers from 1 to 9. Tap a chip or type a value — the preview redraws as you go.
Live resultrows = 5 · 15 numbers
11
12 13
13 14 15
14 15 16 17
15 16 17 18 19
Trace
Worked Walkthrough — rows = 5
Trace how each (i, j) pair maps to 9 + i + j.
i
Values
Count
Prints
1
11
1
11
2
12, 13
2
12 13
3
13, 14, 15
3
13 14 15
4
14..17
4
14 15 16 17
5
15..19
5
15 16 17 18 19
Total numbers = 1 + 2 + … + n = n(n+1)/2 → O(n²).
Code
Python Programs
Three complete programs: fixed rows = 5, custom base with input(), and compact rows = 3. Use View Output for sample results.
Example 1 — Fixed rows = 5
Hard-coded height — print 9 + i + j with a trailing space on each cell.
Python
for i in range(1, 6):
for j in range(1, i + 1):
print(9 + i + j, end=" ")
print()
Output
11
12 13
13 14 15
14 15 16 17
15 16 17 18 19
How It Works
1. Outer grows the width. Row i prints exactly i numbers.
2. Formula fills the cells.9 + i + j makes the first cell 11 and each row start one higher.
3. Newline once. Call print() only after the inner loop finishes.
Example 2 — Custom Base and Rows
Read rows and base_val at runtime, then use base_val + i + j.
Python
rows = int(input("Enter rows: "))
base_val = int(input("Enter base: "))
if rows < 1:
print("Please enter a positive integer for rows.")
else:
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(base_val + i + j, end=" ")
print()
Output (when user enters 3 and 9)
Enter rows: 3
Enter base: 9
11
12 13
13 14 15
How It Works
1. Read and validate. Parse both answers; reject non-positive rows before looping.
2. Same core.base_val replaces hard-coded 9 — use 9 to start at 11.
3. Safer input tip. Bare int(input()) raises ValueError on letters. Prefer:
Safer input
raw = input("Enter rows: ").strip()
try:
rows = int(raw)
except ValueError:
print("Please enter a positive integer.")
raise SystemExit(1)
if rows < 1:
print("Please enter a positive integer.")
raise SystemExit(1)
Example 3 — Compact rows = 3
Same structure with only three rows — easy to confirm the formula on paper.
Python
rows = 3
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(9 + i + j, end=" ")
print()
Output
11
12 13
13 14 15
How It Works
1. Three rows.i = 1 → 11; i = 2 → 12 13; i = 3 → 13 14 15.
2. Trace on paper. If you forget end=" ", numbers glue together (1213).
3. Scale up next. Once the small demo is clear, use Examples 1–2 for five rows or a custom base.
Edge Cases & Pitfalls
Check these before calling the solution done.
wrong base
Offset off by one
Using 10 + i + j or i + j shifts every value — the triangle no longer starts at 11. Keep 9 + i + j.
j <= rows
Rectangle instead of triangle
Inner bound range(1, rows + 1) makes every row the same width. Use range(1, i + 1).
no space
Glued numbers
Without end=" ", values run together (1213). Always print a trailing space.
print() inside
Broken rows
If print() sits inside the inner loop, you get one number per line. Call it only after the loop.
rows = 1
Single value
Output is just 11. A good sanity check for input validation.
input()
Catch ValueError
Letters crash bare int(input()) — wrap in try/except and require rows >= 1.
Analysis
Time and Space Complexity
Program
Time
Extra space
Examples 1–3
O(n²)
O(1)
Row i prints i numbers. Total = 1 + 2 + … + n = n(n+1)/2 → O(n²) time. Only a few loop variables are needed.
Remember
Key Takeaways
Formula: each cell is 9 + i + j — first cell is always 11.
Growing width: inner loop runs j = 1..i so row i has i numbers.
end= vs print(): values with spaces stay on the line; print() advances after each row.
Complexity:O(n²) time from n(n+1)/2 prints; O(1) extra space.
One line: for each row i, print 9 + i + j for j = 1..i with spaces, then print().
Frequently Asked Questions
Because the printed value is 9 + i + j. On the first row i = 1 and j = 1, so 9 + 1 + 1 = 11.
It is a base offset. Change 9 to any base value to shift the entire triangle — see Example 2.
Program 32 uses 9 + i + j (starts at 11). Program 33 uses i + j - 1 (starts at 1).
print(9 + i + j, end=" ") keeps values separated on the same row. print() ends the row.
Replace 5 with rows in the outer loop bound — see Example 2.
O(n²) for n rows because total prints are 1 + 2 + ... + n = n(n+1)/2.
Use try/except ValueError around int(input()) or check the raw string with .isdigit() before converting so bad input does not crash the script.
Only one row prints — a single 11.
Yes — print(base_val + i + j, end=" ") lets the user pick any starting offset.
🤔
Did you know?
Each printed value is computed as 9 + i + j. Row i = 1 prints 11; row i = 2 prints 12 and 13 — a left-shifted increasing triangle.