Shape Rule
rows..i per row
Every row starts at rows — row with stop i = 4 prints 5432; last row prints 54321.

Program 8 prints a reverse left-growing number triangle: each row begins with the peak digit rows and grows by adding the next smaller digit to the right — 5, 54, 543, and so on. This tutorial covers the shape rule, descending outer loop, inner bound rows..i, a live preview, worked Python examples, edge cases, and complexity.
rows..i per row
Every row starts at rows — row with stop i = 4 prints 5432; last row prints 54321.
i = rows..1
for i in range(rows, 0, -1) — moves the inner stop point from rows down to 1.
j = rows..i
for j in range(rows, i - 1, -1) always starts at rows, counts down to i.
Same line / next line
Digits use print(j, end=""); end each row with print().
rows = 3..9
Pick row count and draw the left-growing triangle in the browser.
Complexity
Total prints = 1+2+…+n = n(n+1)/2 — a triangular number.
A reverse left-growing number triangle keeps the same starting digit on every row while adding one more digit to the right each time. With rows = 5, you get 5, 54, 543, 5432, 54321.
In Python use an outer loop counting down from rows to 1, an inner loop printing j from rows down to i, then print() after each row.
It pairs with Program 7’s right-growing triangle — fixed inner start at rows teaches how stop values control row width.
i = rows..1 — stop moves inward.
Fixed start at rows, stop at i.
Program 7 outer up, inner i..1; Program 8 outer down, inner rows..i.
Follow Program 7; continue to Program 9 next.
In short: outer i = rows..1, inner j = rows..i, print(j, end="") per digit, then print().
Given row count rows = 5, print a reverse left-growing number triangle — inner loop prints digits rows..i on each row.
# rows = 5
#5
#54
#543
#5432
#54321 | Item | Type | Description |
|---|---|---|
rows | int | Triangle height — also the peak digit and inner loop start. |
i (outer) | int | Inner loop stop — runs rows down to 1. |
j (inner) | int | Prints rows..i with print(j, end=""). |
| Row width | int | Row with stop i prints rows - i + 1 digits. |
| First row | int | Single digit rows when i = rows. |
| Last row | string | Digits rows..1 when i = 1. |
for i from rows down to 1:
for j from rows down to i:
print j
print newline | Approach | Idea | Best for |
|---|---|---|
| Descending outer | for i in range(rows, 0, -1) | Stop value moves from peak to 1 |
| Inner rows..i | Fixed start at rows, countdown to i | Left-aligned peak digit |
| User-input rows | int(input()) | Flexible height |
| Compact trace | rows = 3 on paper first | Quick dry-runs |
| Spaced output | print(j, end="") | Readable columns |
| Goal | Pattern |
|---|---|
| Outer loop | for i in range(rows, 0, -1) |
| Inner loop | for j in range(rows, i - 1, -1): print(j, end="") |
| End row | print() |
| Program 7 contrast | Program 7: outer up, inner i..1; Program 8: outer down, inner rows..i |
Same reverse left-growing triangle — three ways to set row count and trace the logic.
rows = 5Hard-coded height for demos
int(input())Read row count from console
rows = 3Quick dry-run on paper
i = rows..1Descending stop value
j = rows..iFixed start at rows
Reach for this pattern when teaching fixed inner starts, variable inner stops, and comparing shapes with Program 7.
Natural companion to Program 7 — same triangular print count, fixed start at rows instead of growing from 1.
Fixed inner start rows with changing stop i — concrete bound practice.
Classic nested-loop question — explain outer down, inner rows..i before coding.
Compare this left-growing triangle with the next pattern in the series.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one small program that locks in fixed inner starts, variable stops, and O(n²) thinking.
Choose a row count between 3 and 9 and draw the reverse left-growing number triangle in the browser.
Three complete Python programs — fixed rows, user input, and a compact trace with rows = 3. Click View Output to reveal sample console results.
Print five rows of the reverse left-growing number triangle with nested loops.
rows = 5Hard-coded height — outer loop down, inner loop from rows to i.
rows = 5
for i in range(rows, 0, -1):
for j in range(rows, i - 1, -1):
print(j, end="")
print() Outer i runs 5 down to 1 — inner j always starts at rows and counts down to i.
Read row count from the user with validation.
Configurable height with int(input()) and a positive-rows check.
try:
rows = int(input("Enter the number of rows: "))
if rows <= 0:
raise ValueError
except ValueError:
print("Please enter a positive integer.")
else:
for i in range(rows, 0, -1):
for j in range(rows, i - 1, -1):
print(j, end="")
print() Same nested loops — only the row count comes from console input with safe parsing.
Use rows = 3 for a quick paper trace before larger triangles.
rows = 3 TraceSmall triangle — easy to dry-run on paper before scaling up.
rows = 3
for i in range(rows, 0, -1):
for j in range(rows, i - 1, -1):
print(j, end="")
print() Three rows, six total digits — trace i and j on paper before coding rows = 5.
int rows = 5; sets the peak digit and pattern height.
for i in range(rows, 0, -1) moves the inner stop from 5 down to 1.
for j in range(rows, i - 1, -1) always starts at rows, counts down to i.
print() moves to the next row after each line is printed.
Total printed digits follow triangular numbers: n(n+1)/2, so time complexity is O(n²).
rows = 5Trace each row — outer i is the inner stop, inner j runs from rows down to i.
| Stop (i) | Inner j values | Output line |
|---|---|---|
| 5 | 5 | 5 |
| 4 | 5, 4 | 54 |
| 3 | 5, 4, 3 | 543 |
| 2 | 5, 4, 3, 2 | 5432 |
| 1 | 5, 4, 3, 2, 1 | 54321 |
Total digits printed: 1+2+3+4+5 = 15 = 5×6/2 — the fifth triangular number.
Where this fixed-start countdown pattern shows up beyond the homework prompt.
Inner always begins at rows — teaches how stop values control width.
Example: trace row with i = 3 and watch j print 5, 4, 3.
Program 7 grows from the right starting at 1; Program 8 starts every row at the peak digit.
Example: print both patterns side by side for rows = 5.
Practice print(j, end="") vs print() without complex math.
Example: put print() inside the inner loop by mistake.
Same outer loop — flip inner to ascending for Program 6’s left-growing pattern.
Example: change inner to range(i, rows + 1) for ascending digits.
Triangular totals make O(n²) concrete for beginners.
Example: count printed digits for n = 10 → 55.
Pair the pattern with int(input()) and positive-row checks.
Example: reject rows <= 0 and re-prompt.
Pro Tip: when an interviewer asks for patterns, explain fixed inner start and changing stop first — then write the loops.
Why this pattern earns a permanent spot in beginner Python courses.
Wrong inner start or stop shows up immediately — every row should begin with the peak digit.
Only loops and console output — no arrays or math libraries.
Add spaces, right-align, or flip inner direction 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 each row add one digit on the right.
Small habits that keep reverse left-growing triangle code clean.
Always begin inner loop at j = rows — only the stop i changes per row.
Avoid crashes when the user types letters instead of a number.
Only call print() after the inner loop finishes the row.
Outer range(rows, 0, -1) and inner range(rows, i - 1, -1) — both move toward smaller values.
Trace rows = 3 on paper before coding larger demos.
Pro Tip: if rows no longer start with the peak digit, check whether inner start was changed from rows to i.
Mistakes that commonly break reverse left-growing number triangles.
Rows no longer share the same leading digit — pattern breaks visually.
→ Use for j in range(rows, i - 1, -1).
All digits print on one long line without a row break.
→ Call print() after the inner loop.
Invalid input may print nothing or behave unexpectedly.
→ Validate rows > 0 before the loops.
Letters or empty input raise ValueError when int(input()) is unchecked.
→ Wrap in try/except ValueError and re-prompt on failure.
Ascending digits within each row produce the wrong shape.
→ Inner loop must count down from rows to i.
Check these inputs before calling the solution done.
Prints only 1 — inner loop runs once with j = 1.
Outer loop never runs — print nothing or show a message.
Output 2 then 21 — good quick test.
Reject with validation — outer loop condition fails silently otherwise.
Bare int(input()) raises ValueError — use try/except.
Still O(n²) prints — cap rows for console demos.
Try these variations to lock in the pattern.
range(i, rows + 1) for ascending digitsrows = 3 before codingj = rows — every row starts with the peak digit.n(n+1)/2 — a triangular number. For rows = 5, that is 15 digits.i..rows; Program 8 uses descending inner rows..i — same outer loop.rows down to 1 — e.g. 54321 when rows = 5.Quick Takeaway: outer i = rows..1, inner j = rows..i, print(j, end=""), then print().
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–2) | O(rows²) | O(1) |
| Compact trace (Example 3) | O(rows²) | O(1) |
The reverse left-growing number triangle is a compact nested-loop exercise: fixed inner start at rows, changing stop i, and each row grows one digit wider to the right. Master the fixed rows = 5 version, then try user input with int(input()) and the compact rows = 3 trace.
Practice the three examples above, then continue to Program 9 for the next pattern in the series.
Keep inner start at rows, count down to stop i, and validate row count when reading from the console.
for j in range(rows, i - 1, -1)print() after each inner looprows > 0 for user inputrows = 3 on paper firsti instead of rowsrange(1, i + 1) when the pattern needs countdownprint() inside the inner looprows = 3 dry-run before larger demosPrint the reverse left-growing number triangle the beginner-friendly way.
Row prints rows..i
Definitioni = rows..1
Loopj = rows..i
Loopprint then newline
I/OO(n²) time
AnalysisEach row starts at rows and counts down to i — outer i runs rows..1, inner j prints rows..i — producing 5, 54, 543, and so on. Total prints grow as O(n²).
Move on to the next pattern in the Python number-pattern series.
11 people found this page helpful