Python Number Triangle Pattern (Increasing Jump)

Beginner
5 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

An increasing jump number triangle starts each row at i, then jumps forward with a step m that shrinks after every print — jumps get tighter toward the end of the row.

Remember
Rule: row i starts with i
      then add shrinking step m

1
2 6
3 7 10
4 8 11 13
5 9 12 14 15     ← rows = 5, m starts at 4

Unlike the continuous counter in Program 20, each row resets its start to i and uses a fresh decreasing step.

How to Solve It

Print i first; set m = rows - 1 and k = i + m; then print k while shrinking m.

MethodIdeaBest for
Decreasing stepStart at i; jump with m -= 1Learning, interviews
input() rowsSame loops; m = rows - 1Interactive practice
Custom stepFixed initial m instead of rows - 1Variant practice

Pseudocode

Pseudocode
for i from 1 to rows:
    print i (same line, spaced)
    m = rows - 1
    k = i + m
    for j from 1 to i - 1:
        print k (same line, spaced)
        m = m - 1
        k = k + m
    print newline

Cheat sheet

GoalPattern
Set rowsrows = 5
Outer loopfor i in range(1, rows + 1):
Start rowprint(i, end=" ")
Init stepm = rows - 1; k = i + m
Jump loopfor j in range(1, i): then print / shrink
Print + shrinkprint(k, end=" "); m -= 1; k = k + m
End rowprint()
Custom stepm = 3 instead of rows - 1

Printing Numbers vs Starting a New Line

APIEffectUse for
print(i, end=" ")Stays on the same lineEach number
print()Ends the current lineAfter the jump loop

Print numbers with end=" ", then break once with print(). Putting print() inside the jump loop prints one number per line.

Live Preview

Change the row count and the jump triangle updates instantly (m starts at rows - 1).

Whole numbers from 1 to 9. Tap a chip or type a value — the preview redraws as you go.

Live result 5 rows · 15 values
1 
2 6 
3 7 10 
4 8 11 13 
5 9 12 14 15 

Worked Walkthrough — rows = 3

Trace each outer value of i, the starting step m = 2, and the jumps on that row.

iStartJumps (m shrinks)Printed row
11none1
22+2 → 42 4
33+2 → 5, then +1 → 63 5 6

Each row resets m to rows - 1; within the row, m -= 1 makes later jumps smaller.

Python Programs

Three complete programs: fixed rows = 5, input() rows, and a custom initial step. Use View Output for sample results.

Example 1 — Fixed rows = 5

Hard-coded height — each row starts at i, then jumps with m starting at 4.

Python
rows = 5

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()

How It Works

1. Start the row. Print i first — that is always the leftmost value.

2. Set the jump. m = rows - 1 and k = i + m prepare the first jump value.

3. Shrink and advance. Print k, then m -= 1 and k = k + m for each remaining slot; print() ends the row.

Example 2 — input() Rows

Read the row count at runtime; initial step scales as m = rows - 1.

Python
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()

How It Works

1. Read rows. Convert the prompt answer with int().

2. Scale the step. m = rows - 1 grows with height, so taller triangles jump farther at first.

3. Safer input tip. Bare int(input()) raises ValueError on letters. Prefer:

Safer input
raw = input("Enter the number of rows: ").strip()
try:
    rows = int(raw)
except ValueError:
    print("Enter a positive whole number.")
    raise SystemExit(1)
if rows < 1:
    print("Enter a positive whole number.")
    raise SystemExit(1)

Example 3 — Custom Initial Step m = 3

Keep rows = 5 but start each row with m = 3 for tighter jumps than the default 4.

Python
rows = 5

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()

How It Works

1. Same structure. Outer loop and jump loop match Example 1.

2. Fixed seed. Only the initial m changes — m -= 1 and k = k + m still apply.

3. Compare shapes. Row lengths stay the same; values climb more slowly than with m = rows - 1.

Edge Cases & Pitfalls

Check these before calling the solution done.

m outside

Step not reset

If m is set once before the outer loop, later rows inherit a tiny step. Reset m at the start of every row.

order

Wrong update order

Print k, then m -= 1, then k = k + m. Updating k before decreasing m uses the wrong step.

print() inside

Vertical numbers

If print() is inside the jump loop, each number lands on its own line.

rows = 1

Single number

Output is just 1 — the jump loop never runs.

rows ≤ 0

Empty output

The outer loop never runs. Guard interactive input with rows >= 1.

input()

Catch ValueError

Letters crash bare int(input()) — wrap in try/except and require rows >= 1.

Time and Space Complexity

ProgramTimeExtra space
Examples 1–3O(n²)O(1)

Total numbers printed = 1 + 2 + … + n = n(n+1)/2 → O(n²).

Key Takeaways

  • Rule: row i starts with i, then jumps with a shrinking step m.
  • Reset m: set m = rows - 1 at the start of every row.
  • end= vs print(): numbers stay on the line; print() advances after each row.
  • Complexity: O(n²) for n rows.

One line: print i, then keep adding a step that gets one smaller after every jump.

Frequently Asked Questions

Because the step variable m starts at rows - 1 and decreases after each printed number. Each next value adds the current m, so jumps shrink across the row.
m is the step size used to compute the next printed number in the row. It decreases each time, changing the increment between consecutive outputs.
Row 2 prints i = 2 first. Then m = 4 and k = i + m = 6 — the inner loop prints k once, giving 2 6.
print(i, end=" ") stays on the same line with a trailing space. print() ends the current line. Numbers use end=" "; the row break uses print() after the jump loop.
Total prints are 1+2+…+n = n(n+1)/2 — row i prints exactly i values.
Yes. Set m to a custom value instead of rows - 1 (see Example 3) — smaller steps produce tighter jumps.
O(n²) for n rows because total digit prints equal n(n+1)/2.
Use try/except ValueError around int(input()) so bad input does not crash the script.
The outer loop never runs, so nothing is printed. Validate and prompt again if you want a clear user message.

Did you know?

Each 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.

Next: Odd-Length Number Rows

Continue with the next pattern in the Python number-pattern series.

Program 22 tutorial →

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