Shape Rule
Left-shifted triangle
Row i prints i numbers computed as 9 + i + j.

The increasing number triangle from 11 prints 11, 12 13, 13 14 15, … — a natural step after the number-star diamond in Program 31. This tutorial covers the 9 + i + j formula, nested loops, a live preview, worked Python examples, edge cases, and complexity.
Left-shifted triangle
Row i prints i numbers computed as 9 + i + j.
i = 1..rows
for i in range(1, rows + 1): — one growing row per iteration.
1..i
for j in range(1, i + 1): — prints i values per row.
9 + i + j
Base offset 9 shifts the triangle to start at 11.
3–9 rows
Pick a row count and draw the increasing triangle in the browser.
Complexity
Prints per row = i — total work scales as n².
A left-shifted increasing number triangle prints values from the formula 9 + i + j on each row. With rows = 5, you get 11, 12 13, 13 14 15, and so on.
In Python you use nested loops: outer i = 1..rows, inner j = 1..i, printing (9 + i + j) with a trailing space.
It combines nested loops with an arithmetic formula — a step up from Program 31’s modulus diamond.
Formula for each value.
Growing row width.
When base = 9, i=1, j=1.
Follow Program 31; continue to Program 33 (i + j - 1) next.
In short: outer loop i = 1..rows, inner j = 1..i, print 9 + i + j with a space, then print().
Given rows = 5, print a left-shifted increasing triangle: for each row i, print j = 1..i values of 9 + i + j separated by spaces.
# rows = 5 (conceptual shape)
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(9 + i + j, end=" ")
print() | Item | Type | Description |
|---|---|---|
rows | int | Triangle height — number of lines to print. |
i | int | Outer loop — current row; also part of the formula. |
j | int | Inner loop — column index; runs 1..i per row. |
base | int | Offset in the formula (default 9); first value = base + 2. |
for i from 1 to rows:
for j from 1 to i:
print (9 + i + j) + space
print newline | Approach | Idea | Best for |
|---|---|---|
| Fixed formula | 11, 12 13, … | Learning and interviews |
| Custom base | (baseVal + i + j) | Flexible starting number |
| User-input rows | int(input(...)) | Configurable triangle size |
| Goal | Pattern |
|---|---|
| Outer loop | for i in range(1, rows + 1): |
| Inner loop | for j in range(1, i + 1): |
| Print value | print(9 + i + j, end=" ") |
| End the row | print() |
| Custom base | print(baseVal + i + j, end=" ") |
| User input | int(input(...)) |
Same increasing triangle — different ways to control rows and the base offset.
i = 1..rowsOne growing row per iteration
9 + i + jStarts at 11
j = 1..ii values per row
base + 2First printed number
Reach for this pattern when teaching formula-based output, growing inner loops, and arithmetic in nested loops.
Natural follow-up after Program 31 — introduces an arithmetic formula instead of modulus.
Outer/inner bound practice with an immediate visual check.
Combine loops with input() for a flexible row count.
Compare Program 31 (number-star diamond) and Program 33 (i + j - 1) next.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one small program that locks in nested loops, output sequencing, and O(n²) thinking.
Choose a row count between 3 and 9 and draw the increasing triangle in the browser.
Three complete Python programs — fixed rows, custom base input, and a smaller trace demo. Click View Output to reveal sample console results.
Print five rows of the increasing triangle with the 9 + i + j formula.
rows = 5Hard-coded row count — ideal for first demos and screenshots.
for i in range(1, 6):
for j in range(1, i + 1):
print(9 + i + j, end=" ")
print() When i = 1, the inner loop prints 9+1+1 = 11. When i = 3, it prints 13, 14, 15 — output 13 14 15.
Read row count and base offset with input() and int() instead of hard-coding 5 and 9.
Read rows and baseVal with input() and int() instead of hard-coding 5 and 9.
rows = int(input("Enter rows: "))
baseVal = int(input("Enter base: "))
if rows < 1:
raise SystemExit
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(baseVal + i + j, end=" ")
print() Same formula core as Example 1; baseVal replaces hard-coded 9 and rows replaces 5. Non-numeric input raises ValueError with bare int(input()) — use try/except for safer labs.
Run with rows = 3 to trace every row on paper before scaling up.
rows = 3Same nested-loop formula with a smaller row count for quick tracing.
rows = 3
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(9 + i + j, end=" ")
print() Only rows changes from 5 to 3 — the nested-loop formula stays identical. Trace i = 1, 2, 3 on paper to see how each row adds one more value.
No imports needed for fixed rows; use input() when reading. Set rows = 5 and loop variables i, j.
for i in range(1, rows + 1): — one growing row per iteration.
for j in range(1, i + 1): — prints i values per row.
print(9 + i + j, end=" ") — each value from the arithmetic formula.
print() ends the row after the inner loop finishes.
Prints per row = i — O(n²) time, O(1) extra memory.
rows = 5Trace each outer-loop value of i, inner-loop range, values printed, and full row output.
i | Inner range (j) | Values (9+i+j) | Row output |
|---|---|---|---|
1 | 1 | 11 | 11 |
2 | 1, 2 | 12, 13 | 12 13 |
3 | 1, 2, 3 | 13, 14, 15 | 13 14 15 |
4 | 1..4 | 14, 15, 16, 17 | 14 15 16 17 |
5 | 1..5 | 15, 16, 17, 18, 19 | 15 16 17 18 19 |
Prints per row = i — total prints = n(n+1)/2 for n rows.
Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.
Clearest visual proof that outer and inner bounds interact.
Example: change inner bound to j <= rows and watch every row print the same width.
Foundation for formula-based triangles, custom bases, and left-shifted sequences.
Example: continue to Program 33 for the i + j - 1 variant starting at 1.
Practice print vs row newline without complex math.
Example: put print() inside the inner loop by mistake.
Add spaces between digits once the two-loop structure works.
Example: use print(j, end=" ") between digits for wider spacing.
Triangular totals make O(n²) concrete for beginners.
Example: count printed numbers for rows = 5 — total is 1+2+3+4+5 = 15.
Pair the pattern with try/except ValueError and positive-row checks.
Example: reject rows <= 0 and re-prompt.
Pro Tip: when an interviewer asks for patterns, explain the outer/inner roles first — then write the loops. The story matters as much as the code.
Why this pattern earns a permanent spot in beginner Python courses.
Wrong bounds show up immediately as a broken staircase.
Only loops and console output — no arrays or math libraries.
Invert, center, hollow, or change the fill character with small edits.
Streaming output needs no storage beyond loop counters.
Pro Tip: trace i and j on paper for rows = 3 before coding — watch how each row prints i values starting at 9 + i + 1.
Small habits that keep number-pattern code clean.
Inner bound must be j <= i — row i prints exactly i numbers.
try/except ValueErrorUse try/except ValueError so bad input does not crash when converting values.
Only call print() after the inner loop finishes the row.
Write the formula for each (i, j) pair before coding the loops.
Trace i = 1..3 on paper before coding the full rows = 5 demo.
Pro Tip: if the output is a vertical list of single digits per line, you almost certainly put print() inside the inner loop.
Mistakes that commonly break increasing number triangles.
Each digit lands on its own line — you get a column, not a triangle.
→ Use print(9 + i + j, end=" "); print() only after the inner loop.
Using i + j or 10 + i + j shifts every value — the triangle no longer starts at 11.
→ Keep 9 + i + j (or base + i + j with base = 9).
j <= rows prints a rectangle — every row has the same width.
→ Keep for j in range(1, i + 1): so row i prints i values.
Printing numbers without a space makes multi-digit values run together on wider rows.
→ Append a space after each number: print(9 + i + j, end=" ").
int(input())Letters or empty input raise ValueError with bare int(input()).
→ Catch ValueError and re-prompt on failure.
Check these inputs before calling the solution done.
Output is just 11 — one value, one row.
Outer loop never runs — print nothing or show a message.
rows < 0Treat as invalid; re-prompt instead of silent empty output.
Two rows: 11 and 12 13.
Bare int(input()) raises ValueError on bad input — use try/except first.
Total prints = n(n+1)/2 — grows quadratically with row count.
Try these variations to lock in the pattern.
9 with a user-entered baseVali + j - 1 instead of 9 + i + jrows >= 1 after reading input9 + i + j. Inner loop runs j = 1..i — row i prints i numbers.print(9 + i + j, end=" ") stays on the line; print() advances — mix them carefully.rows > 0 for interactive programs; rows = 1 prints a single 11.9 to any base to shift the whole triangle — compare with Program 33 where the formula is i + j - 1.Quick Takeaway: outer loop i = 1..rows, inner j = 1..i, print 9 + i + j, then print().
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–3) | O(n²) | O(1) |
| Smaller demo (Example 3) | O(n²) | O(1) |
The increasing number triangle from 11 is a compact lesson in formula-based nested loops: compute each value with 9 + i + j, grow the inner bound to i, and end each row with print(). Master the fixed-rows version, then try user input and a smaller trace demo.
Practice the three examples above, then continue to Program 33 for the i + j - 1 variant starting at 1.
Inner bound must be j <= i — validate rows when reading from the console.
for i in range(1, rows + 1): in the outer loopfor j in range(1, i + 1): prints i valuesprint(9 + i + j, end=" ")int(input()) in try/except ValueErrorprint() inside the inner loopj <= rows in the inner loop (prints a rectangle)rows = 1 edge casePrint the pattern the beginner-friendly way.
9 + i + j
Definitionj = 1..i
CodeStarts at 11
Codeprint() after the inner loop
O(n²) time
AnalysisEach 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.
Move on to the increasing number triangle starting from 1 (i + j - 1) in the Python number-pattern series.
12 people found this page helpful