Shape Rule
Jump sequence
Row 1 prints 1, row 2 prints 2 6, row 3 prints 3 7 10, and so on with shrinking jumps.

The increasing jump number triangle starts each row at i and jumps forward with a decreasing step m — a natural step after the continuous counter in Program 20. This tutorial covers the shape rule, step logic, a live preview, algorithm steps, worked Python examples, edge cases, and complexity.
Jump sequence
Row 1 prints 1, row 2 prints 2 6, row 3 prints 3 7 10, and so on with shrinking jumps.
1..rows
for i in range(1, rows + 1) makes row i print exactly i numbers.
m -= 1 each jump
Set m = rows - 1 and k = i + m; after each print do m -= 1 then k = k + m.
Same line / next line
Print i first, then k values in the inner loop; end each row with print().
1–15 rows
Pick a row count and draw the jump number triangle instantly in the browser.
Complexity
Total prints = rows(rows+1)/2; extra memory stays O(1).
An increasing jump number triangle prints each row starting at the row index, then jumps forward using a step that shrinks after every print. With rows = 5, the output is 1, 2 6, 3 7 10, 4 8 11 13, 5 9 12 14 15.
In Python you print i first, set m = rows - 1 and k = i + m, then in the inner loop print k, do m -= 1, and update k = k + m before the next value.
It combines nested loops with a changing step variable — a step up from Program 20’s simple counter.
Print i before the inner loop on every row.
Start at rows - 1 and decrease after each jump.
k = i + m first, then m -= 1 and k = k + m in the loop.
Follow Program 20; continue to Program 22 (odd-length rows) next.
In short: for each row i, print i, then use a decreasing step m to compute and print the remaining i - 1 values.
Given a positive integer rows, print an increasing jump number triangle: row i starts with i, then prints i - 1 more values computed by adding a decreasing step m.
# rows = 5 (conceptual shape)
# 1
# 2 6
# 3 7 10
# 4 8 11 13
# 5 9 12 14 15 | Item | Type | Description |
|---|---|---|
rows | int | Number of triangle lines to print (typically ≥ 1). |
m | int | Step size — starts at rows - 1, decreases after each jump. |
k | int | Next value to print — set to i + m before the inner loop. |
| Printed output | text | Row i has i spaced numbers with shrinking jumps. |
for i from 1 to rows:
print i
m = rows - 1
k = i + m
for j from 1 to i - 1:
print k
m = m - 1
k = k + m
print newline | Approach | Idea | Best for |
|---|---|---|
| Decreasing step m | 1, 2 6, 3 7 10, … | Learning and interviews |
| User-input rows | rows = int(input(...)) | Flexible console programs |
| Custom initial step | m = 3 instead of rows - 1 | Tighter or wider jumps |
| Goal | Pattern |
|---|---|
| Walk each row | for i in range(1, rows + 1) |
| Print row start | print(i, end=" ") |
| Init step | m = rows - 1 |
| First jump value | k = i + m |
| Inner loop | for j in range(1, i) |
| Update step | m -= 1 then k = k + m after each print |
| User input | rows = int(input(...)) |
Same jump triangle — different ways to control rows and step size.
print(i)Every row begins with the row index
m = rows-1Initial jump size — reset each row
m = 3Override step in Example 3
m -= 1Decrease m after each k print — jumps shrink
Reach for this pattern when teaching variable step sizes and computed sequences inside nested loops.
Natural follow-up after Program 20 — introduces a decreasing step variable.
Outer/inner bound practice with an immediate visual check.
Combine loops with input() for a flexible row count.
Compare Program 20 (continuous counter) and Program 22 (odd-length rows) 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 1 and 15 and draw the jump number triangle in the browser.
Three complete Python programs — fixed row count, user input, and custom initial step for m. Click View Output to reveal sample console results.
Print five rows of the jump number triangle with a decreasing step.
rows = 5Hard-coded height — ideal for first demos and screenshots.
rows = 5
for i in range(1, rows + 1):
print(i, end=" ")
m = 4
k = i + m
for j in range(1, i):
print(k, end=" ")
m -= 1
k = k + m
print() When i = 2, print 2, then m = 4 and k = 6 — the inner loop prints 6 once. When i = 3, print 3, then k = 7, m -= 1 to 3, k = 10 — output 3 7 10. print() after the inner loop starts the next row.
Read the row count with input() instead of hard-coding 5.
Read rows with input() and int(); set m = rows - 1 each row.
rows = int(input("Enter the number of rows: "))
for i in range(1, rows + 1):
print(i, end=" ")
m = rows - 1
k = i + m
for j in range(1, i):
print(k, end=" ")
m -= 1
k = k + m
print() Same nested-loop core as Example 1; only the source of rows changes. m = rows - 1 scales the initial jump with triangle height. Non-numeric input raises ValueError from int(input()) — wrap it in try/except in safer labs.
Use a fixed initial step instead of rows - 1.
m = 3Keep rows = 4 but start each row with m = 3 for tighter jumps.
rows = 4
for i in range(1, rows + 1):
print(i, end=" ")
m = 3
k = i + m
for j in range(1, i):
print(k, end=" ")
m -= 1
k = k + m
print() Change only the initial value of m — the inner loop and k = k + m logic stay the same. Smaller starting steps produce tighter jumps within each row.
print is built in; use input() when reading input. Set rows and loop variables i, j, k, m.
for i in range(1, rows + 1) then print(i, end=" ") — row i prints i numbers.
m = rows - 1 and k = i + m set up the first jump in that row.
Print k, then m -= 1 and k = k + m to compute the next jump.
print() ends the row so the next outer iteration starts fresh.
Total prints: rows(rows+1)/2 — O(n²) time, O(1) extra memory.
rows = 5Trace each outer-loop value of i, the initial m, and the numbers printed on each row.
i | Init m | Jump sequence | Row output |
|---|---|---|---|
1 | 4 | 1 (no inner loop) | 1 |
2 | 4 → k=6 | 2, 6 | 2 6 |
3 | 4 → k=7, m=3 → k=10 | 3, 7, 10 | 3 7 10 |
4 | 4 → 8, 11, 13 | 4, 8, 11, 13 | 4 8 11 13 |
5 | 4 → 9, 12, 14, 15 | 5, 9, 12, 14, 15 | 5 9 12 14 15 |
Total number prints: 1 + 2 + 3 + 4 + 5 = 15 = 5×6/2.
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 j <= i and watch the shape change.
Foundation for inverted, pyramid, diamond, and hollow variants.
Example: use (i + j) % 2 for row+column parity grids.
Practice print(..., end=" ") vs row newline without complex math.
Example: put print() inside the inner loop by mistake.
Swap digits for letters, stars, or spaced output once the loop works.
Example: print k with end=" " for spaced digits on each row.
Triangular totals make O(n²) concrete for beginners.
Example: count printed digits for n = 10 still → 55.
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 C 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: learn m = rows - 1 and k = i + m first; compare with custom step in Example 3.
Small habits that keep number-pattern code clean.
Reset m = rows - 1 at the start of each row — not once before all loops.
input()Wrap int(input()) in try/except ValueError so bad input does not crash the script.
print() OutsideOnly call print() after the inner loop finishes the row.
Write row i, initial m, and each k jump before coding.
Trace rows = 5 on paper before coding larger demos.
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 jump number patterns.
Each digit lands on its own line — you get a column, not a triangle.
→ Use print(i, end=" ") and print(k, end=" "); print() only after the inner loop.
Using j <= i prints one extra value per row.
→ Use for j in range(1, i) — only i - 1 jumps after printing i.
Skipping m -= 1 makes every jump the same size.
→ Always do m -= 1 then k = k + m after printing k.
Omitting print() glues every number onto one endless line.
→ Always end the row after the inner loop.
Letters or empty input raise ValueError from int(input()).
→ Prefer try/except ValueError and re-prompt on failure.
Check these inputs before calling the solution done.
Output is just 1 on one line.
Outer loop never runs — print nothing or show a message.
rows < 0Treat as invalid; re-prompt instead of silent empty output.
Output grows as n² characters — fine for labs, noisy for huge n.
int(input()) raises ValueError — validate with try/except first.
Declaring m once before all loops gives wrong jumps — reset inside each row.
When i = 1, the inner loop runs zero times — only 1 prints.
Try these variations to lock in the pattern.
k++ across rowsm = 2 or m = 6 instead of rows - 1rows(rows+1)/2 — O(n²) for n rows.print(k, end=" ") stays on the line; print() advances — mix them carefully.rows > 0 for interactive programs; rows = 1 should print a single 1.Quick Takeaway: print i first, set m = rows - 1 and k = i + m, then loop with m -= 1 and k = k + m.
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–2) | O(rows²) | O(1) |
| Custom step (Example 3) | O(rows²) | O(1) |
The increasing jump number triangle is a compact lesson in variable step sizes: print i, set m = rows - 1, compute jumps with k = i + m, and shrink m after each print. Master the fixed-rows version, then try user input and a custom step value.
Practice the three examples above, then continue to Program 22 for odd-length number rows.
Reset m each row — use j < i for the inner loop and validate rows when reading input.
i before the inner loop on every rowm = rows - 1 inside each outer iterationfor j in range(1, i) for jump valuesint(input()) in try/except ValueError before using rowsprint() inside the inner jump loopj <= i — that prints one extra valuem -= 1 before updating krows = 1 edge casePrint the pattern the beginner-friendly way.
Jump + m -= 1
DefinitionRow start first
Coderows - 1, then m -= 1
CodeRow i prints i nums
ShapeO(n²) time
AnalysisEach row starts at i, then adds a decreasing step m to compute the next value. As m shrinks after each print, the jumps get smaller toward the end of the row — total prints still equal n(n+1)/2 for n rows.
Move on to the odd-length number rows pattern in the Python number-pattern series.
12 people found this page helpful