Shape Rule
A..end letter, shrinking rows
Row 1 prints ABCDE (all rows letters), then ABCD, …, down to a single A.

The decreasing alphabet pattern is the mirror of Program 1’s growing triangle: the first row is longest, each line drops one letter at the end. This tutorial covers the shape rule, reverse outer loop, a live preview, algorithm steps, worked Python examples, edge cases, and complexity.
A..end letter, shrinking rows
Row 1 prints ABCDE (all rows letters), then ABCD, …, down to a single A.
Rows
for i in range(rows, 0, -1): picks how many letters each row prints — longest first.
Letters
for code in range(base, base + i): still prints letters from A; only the outer bound i shrinks each row.
Same line / next line
Letters use print(..., end=""); end each row with print().
1–26 rows
Pick a row count and draw the decreasing alphabet pattern instantly in the browser.
Complexity
Total letters = n(n+1)/2; extra memory stays O(1).
A decreasing alphabet pattern starts with the longest row and shortens by one letter each line. With five rows the console shows ABCDE, ABCD, ABC, AB, A — the inverse of Program 1’s growing triangle.
In Python you solve it with two nested for loops: the outer loop walks i from rows down to 1, the inner loop prints letters from A through i characters, then print() moves to the next line.
It reinforces reverse outer-loop bounds — the same inner letter logic as Program 1, flipped. Once range(rows, 0, -1) clicks, inverted stars, numbers, and more patterns follow naturally.
On row i, print i letters from A; first row has rows letters.
range(rows, 0, -1) walks longest row first.
print(chr(code), end="") in the inner loop; print() after.
Same inner loop; only outer direction differs from the increasing triangle.
In short: for each row i from rows down to 1, print letters from A with print(chr(code), end=""), then call print().
Given a positive integer rows, print a left-aligned decreasing alphabet pattern: the first line has rows letters from A, each next line one fewer, ending with A.
# First 5 rows (conceptual shape)
# ABCDE
# ABCD
# ABC
# AB
# A | Item | Type | Description |
|---|---|---|
rows | int | Number of triangle lines to print (typically ≥ 1). |
| Printed output | text | Left-aligned rows of letters; first row has rows letters from A, each row one shorter. |
for i from rows down to 1:
for j from 1 to i:
print next letter from A (no newline)
print newline | Approach | Idea | Best for |
|---|---|---|
| Nested loops | Decreasing outer + inner letters from A | Learning and interviews |
| Reverse outer loop | for i in range(rows, 0, -1) | Decreasing row lengths — this pattern |
letters[:i] | Slice first i letters with decreasing i | Shorter production-style demos |
| Goal | Pattern |
|---|---|
| Walk each row (decreasing) | for i in range(rows, 0, -1): |
Print A..end letters | for code in range(base, base + i): print(chr(code), end="") |
| End the row | print() |
| One-line row shortcut | print(letters[:i]) inside decreasing outer loop |
| Growing variant | Use range(1, rows + 1) — see Program 1 |
Same decreasing pattern — different ways to emit characters.
same linePrints a letter without moving to the next line
new lineEnds the current row after all letters are printed
whole rowBuilds letters A..end at once — skip the inner loop
loops firstMaster nested loops before the string shortcut
Reach for this pattern when teaching reverse outer loops or mirroring Program 1’s growing triangle.
Natural follow-up after Program 1 — same inner logic, outer loop counts down.
Practice range(rows, 0, -1) with an immediate visual check.
Combine loops with input() for a flexible row count.
Leads to left-trim patterns, pyramids, and hollow shapes in the series.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one small program that locks in reverse outer loops, output sequencing, and O(n²) thinking — the mirror image of Program 1.
Choose a row count between 1 and 20 and draw the decreasing alphabet pattern in the browser.
Three complete Python programs — fixed row count, CLI input, and a letters[:i] shortcut. Click View Output to reveal sample console results.
Print five rows with classic nested loops — longest row first.
rows = 5Hard-coded height — ideal for first demos and screenshots.
rows = 5
base = ord('A')
for i in range(rows, 0, -1):
for code in range(base, base + i):
print(chr(code), end="")
print() When i = 5, the inner loop prints ABCDE. When i = 4, it prints ABCD, and so on until i = 1 prints a single A. print() after the inner loop starts the next row.
Let the user choose the height at runtime.
Read the row count with input() and convert with int() (wrap in try/except ValueError in real apps).
rows = int(input("Enter the number of rows (max 26): "))
rows = max(1, min(rows, 26))
base = ord('A')
for i in range(rows, 0, -1):
for code in range(base, base + i):
print(chr(code), end="")
print() Same ord/chr core as Example 1; only the source of rows changes. The outer loop still counts down from the clamped value. Non-numeric input raises ValueError with bare int(input()) — use try/except for safer labs.
Same shape without an explicit inner letter loop.
letters[:i]Slice A–Z for each shrinking row length with letters[:i] inside a decreasing outer loop.
rows = 5
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(rows, 0, -1):
print(letters[:i]) letters[:i] returns the first i letters of the alphabet. With i counting down from rows, you get the same ABCDE-to-A shape without an explicit inner loop. Keep the two-loop version for exams that ask you to show both bounds.
Use input() when reading input. Set rows (fixed or from CLI) and clamp to 1–26 for A–Z.
for i in range(rows, 0, -1): selects how many letters the current line prints — longest first.
for code in range(base, base + i): prints each letter with print(chr(code), end="").
print() ends the row so the next outer iteration starts fresh.
Total letters: n+(n-1)+…+1 = n(n+1)/2 — O(n²) time, O(1) extra memory.
rows = 4Trace each outer-loop value i (counting down) and see what the inner loop prints from A.
Outer i | Inner code range | Printed row | Letters this row |
|---|---|---|---|
4 | A..D | ABCD | 4 |
3 | A..C | ABC | 3 |
2 | A..B | AB | 2 |
1 | A..A | A | 1 |
Total letter prints: 4 + 3 + 2 + 1 = 10 = 4×5/2. Same triangular total as Program 1 — only row order differs.
Where this shrinking letter pattern (and its reverse outer loop) shows up beyond the homework prompt.
Clearest visual proof that range(rows, 0, -1) shrinks row length each iteration.
Example: compare side-by-side with Program 1.
Natural step after Program 1 before left-trim and pyramid letter patterns.
Example: Program 6 shifts the start letter each row.
Practice character loops and print(..., end="")/print() with a shape that differs visibly from Program 1.
Example: swap outer loop direction and compare outputs.
Swap to lowercase or digits once the letter loop works.
Example: print lowercase a..z once uppercase clicks.
Triangular totals make O(n²) concrete for beginners.
Example: count printed letters 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 the decreasing variant, explain that only the outer loop changes — inner letter logic matches Program 1.
Why this decreasing pattern earns a spot after Program 1 in beginner Python courses.
Side-by-side with Program 1 makes reverse outer loops obvious.
Only loops and console output — no arrays or math libraries.
One-line outer-loop change flips between growing and shrinking shapes.
Streaming output needs no storage beyond loop counters.
Pro Tip: master Program 1 first, then this page — the inner loop is identical; only range(rows, 0, -1) is new.
Small habits that keep decreasing alphabet-pattern code clean.
Use rows (or n) and keep i/j for row/column — or rename to row/col.
int(input()) in try/exceptAvoid crashes when the user types letters instead of a number.
Only call print() after the inner loop finishes the row.
range(rows, 0, -1) matches “first row longest, each row one shorter” naturally.
Trace rows = 3 on paper — expect ABC, AB, A — before coding larger demos.
Pro Tip: if the output is a vertical list of single letters, you almost certainly put print() inside the inner loop.
Mistakes that commonly break decreasing alphabet patterns.
Each letter lands on its own line — you get a column, not a shrinking row pattern.
→ Use print(..., end="") for letters; print() only after the inner loop.
range(1, rows + 1) prints Program 1’s growing triangle, not ABCDE-to-A.
→ For this shape, use range(rows, 0, -1).
Omitting print() after the inner loop glues every letter onto one endless line.
→ Always end the row after the inner loop.
Non-numeric input raises ValueError with bare int(input()).
→ Wrap in try/except ValueError and validate range.
Copying Program 1’s outer loop produces A, AB, ABC — the opposite shape.
→ Decreasing pattern: outer counts down; inner still uses range(base, base + i).
Check these inputs before calling the solution done.
Output ends with just A on the last 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.
int(input()) raises ValueError — validate first.
Same loops work with #, digits, or letters.
Try these variations to lock in the decreasing pattern.
1 to rowschr(code) with digit logictry/except ValueError until rows >= 1n(n+1)/2 — same as Program 1, only row order differs.print(..., end="") stays on the line; print() advances — mix them carefully.rows > 0 for interactive programs; rows = 1 should print a single A (one row only).Quick Takeaway: outer loop counts down from rows, inner loop prints A..end, then break the line — mirror of Program 1.
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–2) | O(rows²) | O(1) |
letters[:i] (Example 3) | O(rows²) | O(rows) per row string (temporary) |
The decreasing alphabet pattern is a compact reverse-loop exercise with lasting payoff: range(rows, 0, -1), the same inner letter logic as Program 1, and O(n²) intuition. Master the classic two-loop version, then optionally shorten rows with letters[:i] inside the decreasing outer loop.
Practice the three examples above, then continue to Program 6 for the next left-trim variant in the series.
First row has rows letters — keep print(..., end="") for letters and print() for the break, and validate row counts when reading input.
rows down to 1), inner = A..end codesfor i in range(rows, 0, -1): for the decreasing outer loopprint(chr(code), end="") for letters and print() after each rowrows ≥ 1 for interactive programsint(input()) in try/except ValueErrorprint() inside the inner letter looprange(1, rows + 1) when you meant the decreasing patternrows = 1 edge casePrint ABCDE-to-A the beginner-friendly way.
First row longest, then shrink
Definitionrange(rows, 0, -1)
CodePrints A..end with print
CodeEnds each row
I/OO(n²) time
AnalysisRow i prints letters from A through the i-th letter, with i shrinking each row: ABCDE, ABCD, …, A. Total letters for n rows is still n(n+1)/2 — O(n²).
Shift the start letter each row for the next alphabet pattern in the series.
12 people found this page helpful