Shape Rule
1..i digits on row i
Row 1 prints 1, row 2 prints 12, growing until row rows prints 1..rows.

The ascending number triangle pattern grows one digit per row: nested loops, print(..., end="") vs print(), and a clear visual result. This tutorial covers the shape rule, loop structure, a live preview, algorithm steps, worked Python examples, edge cases, and complexity.
1..i digits on row i
Row 1 prints 1, row 2 prints 12, growing until row rows prints 1..rows.
Rows
for i in range(1, rows + 1): walks each line from one digit up to the full width.
Digits
for j in range(1, i + 1): prints digits 1 through i on that row.
Same line / next line
Digits use print(j, end=""); end each row with print().
1–20 rows
Pick a row count and draw the ascending number triangle instantly in the browser.
Complexity
Total digit prints = n(n+1)/2; extra memory stays O(1).
An ascending number triangle pattern starts with one digit on row 1 and grows by one digit each row. Each row prints consecutive digits from 1 up to i, expanding from top to bottom.
In Python you solve it with two nested for loops: the outer loop picks the row, the inner loop prints digits 1..i on that row, then print() moves to the next line.
It is a natural follow-up after Program 4’s left-aligned descending triangle. Once nested loops and print(..., end="")/print() click, pyramids, diamonds, and hollow shapes become much easier.
On row i, print digits 1 through i.
Outer counts up rows; inner prints digits 1..i.
print(j, end="") in the inner loop; print() after.
Natural step after Program 4; gateway to pyramid and hollow patterns.
In short: for each row i from 1 up to rows, print digits 1..i with print(j, end=""), then call print().
Given a positive integer rows, print an ascending number triangle: each row i shows digits 1 through i, with the outer loop counting from 1 up to rows.
# rows = 5
//1
//12
//123
//1234
//12345 | Item | Type | Description |
|---|---|---|
rows | int | Number of triangle lines to print (typically ≥ 1). |
| Printed output | text | Each row prints 1..i; the first row has one digit, the last row has rows digits. |
for i from 1 to rows:
for j from 1 to i:
print j (no newline)
print newline | Approach | Idea | Best for |
|---|---|---|
| Nested loops | Outer rows + inner digits | Learning and interviews |
| Spaced output | print(j, end=" ") | Easier reading per row |
| Goal | Pattern |
|---|---|
| Walk each row | for i in range(1, rows + 1): |
Print digits 1..i | for j in range(1, i + 1): print(j, end=""); |
| End the row | print(); |
| Spaced digits | print(j, end=" "); |
| Program 1 contrast | for i in range(rows, 0, -1): (descending outer) |
Same ascending number triangle — different ways to control rows and formatting.
i = 1..rowsCounts up each row — triangle grows
j = 1..iPrints ascending digits per row
print(j, end=" ")Optional space between numbers on each row
int(input())Validate row count when reading user input
Reach for this triangle when teaching or testing nested-loop basics.
Natural follow-up after Program 4 — same inner loop but the outer loop counts up instead of shrinking rows.
Outer/inner bound practice with an immediate visual check.
Combine loops with int(input()) for a flexible row count.
Compare Program 1 (descending outer) and Program 6 (next in series) 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 ascending number triangle in the browser.
Three complete Python programs — fixed rows, user input, and a spaced-output variant. Click View Output to reveal sample console results.
Print five rows of the ascending number triangle with nested loops.
rows = 5Hard-coded height — ideal for first demos and screenshots.
rows = 5
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(j, end="")
print() When i = 1, the inner loop prints 1. When i = 5, it prints 12345 — each row adds one more digit. print() after the inner loop starts the next row.
Let the user choose the height at runtime.
Read rows with int(input()) and validate the result.
try:
rows = int(input("Enter the number of rows: "))
except ValueError:
print("Please enter a positive integer.")
raise SystemExit(1)
if rows < 1:
raise SystemExit(1)
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(j, end="")
print() Same inner-loop core as Example 1; only the source of rows changes from a literal to user input.
Add a space between digits for easier reading on each row.
Keep rows = 5 but print each digit followed by a space.
rows = 5
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(j, end=" ")
print() Only the print statement changes — print(j, end=" ") instead of print(j, end=""). Loop bounds stay the same as Example 1.
No imports needed. Set rows (fixed or from input).
for i in range(1, rows + 1): selects the current line, starting at one digit and growing.
for j in range(1, i + 1): prints digits 1..i with print(j, end="").
print() ends the row so the next outer iteration starts fresh.
Total digit prints: 1+2+…+n = n(n+1)/2 — O(n²) time, O(1) extra memory.
rows = 5Trace each outer-loop value of i (counting up) and count how many digits the inner loop prints.
i | Inner j range | Printed row | Digits this row |
|---|---|---|---|
1 | 1..1 | 1 | 1 |
2 | 1..2 | 12 | 2 |
3 | 1..3 | 123 | 3 |
4 | 1..4 | 1234 | 4 |
5 | 1..5 | 12345 | 5 |
Total digit 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: Program 4 shrinks each row from rows down to i.
Practice print(j, end="") vs print() 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: use print(j, end=" ") for spaced digits on each row.
Triangular totals make O(n²) concrete for beginners.
Example: count printed digits for n = 10 → 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 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 grows by one digit.
Small habits that keep number-pattern code clean.
Use rows (or n) and keep i/j for row/column — or rename to row/col.
try/except ValueErrorAvoid crashes when the user types letters instead of a number.
Only call print() after the inner loop finishes the row.
1..rows with j <= i matches “row i prints digits 1..i” naturally.
Trace rows = 3 on paper before coding larger demos.
Pro Tip: if the output is a vertical list of single digits, you almost certainly put print() inside the inner loop.
Mistakes that commonly break ascending number triangles.
Each digit lands on its own line — you get a column, not a triangle.
→ Use print(j, end="") for digits; print() only after the inner loop.
j <= rows prints a rectangle; wrong outer bounds flatten or invert the shape.
→ For this shape, keep j <= i.
Omitting print() glues every digit onto one endless line.
→ Always end the row after the inner loop.
int(input())Letters or empty input raise ValueError with bare int(input()).
→ Catch ValueError and re-prompt on failure.
Switching to i = 0 without adjusting the inner bound prints an empty first row or wrong counts.
→ If 0-based, print digits 1..i+1 (e.g. j <= i + 1).
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²/2 characters — fine for labs, noisy for huge n.
Bare int(input()) raises ValueError — use try/except first.
Try print(j, end=" ") for spaces between numbers.
Try these variations to lock in the pattern.
print(j, end=" ") between digitsn(n+1)/2 — hence O(n²) time.print(..., end="") stays on the line; print() advances — mix them carefully.rows > 0 for interactive programs; rows = 1 should print a single 1.Quick Takeaway: outer loop picks the row, inner loop prints digits 1..i, then break the line — that is the whole pattern.
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–2) | O(rows²) | O(1) |
| Spaced output (Example 3) | O(rows²) | O(1) |
The ascending number triangle pattern is a small nested-loop exercise with lasting payoff: row/column thinking, print(..., end="") vs print(), and O(n²) intuition. Master the fixed-rows version, then try user input and spaced output.
Practice the three examples above, then continue to Program 6 for the next pattern in the series.
Row i prints 1..i — keep print(j, end="") for digits and print() for the break, and validate row counts when reading input.
for i in range(1, rows + 1): in the outer loopprint(j, end="") for digits and print() after each rowrows ≥ 1 for interactive programstry/except ValueError when reading user inputprint() inside the inner digit looprows = 1 edge casePrint the triangle the beginner-friendly way.
Row i prints 1..i
DefinitionControls each row
CodePrints digits with print(j, end="")
print() ends each row
O(n²) time
AnalysisRow i prints digits 1 through i. The outer loop counts up from 1 to rows, so each row grows by one digit — still O(n²) total prints.
Move on to the next pattern in the Python number-pattern series.
11 people found this page helpful