Top Half
range(rows)
Same widening row rule as Program 33 — r = 0 .. rows-1.

An alphabet diamond mirrors the widening rows from Program 33: apex A, then B B, C C, up to the widest row E E, then the same rows in reverse down to A. The top half uses range(rows); the bottom half uses range(rows - 2, -1, -1) so the widest row is not printed twice. Total lines: 2*rows - 1. This is the final program in the alphabet pattern series — next up: Python Number Pattern Programs. Includes live preview, worked Python examples, edge cases, and complexity.
range(rows)
Same widening row rule as Program 33 — r = 0 .. rows-1.
range(rows-2, -1, -1)
Mirror rows downward starting at rows - 2 — skips the widest row already printed.
chr(base + r)
ch = chr(base + r) picks the row letter — A on row 0, E on row 4 for half height 5.
2*r - 1
if r > 0: print (2 * r - 1) gap spaces and the same letter again — row 0 stays a single A.
1–26 half height
Pick half height and draw the full alphabet diamond in the browser instantly.
Total lines
Half height rows=5 prints 9 lines; widest row appears once — O(n²) time, O(1) extra memory.
An alphabet diamond combines the widening rows from Program 33 into a full symmetric shape: grow from centered A to the widest letter row, then shrink back to A without repeating the middle line. Row 0 prints a single A; each next row steps to the next letter — B B, C C, until the widest row, then the mirror runs in reverse.
In Python you solve it with two loops sharing the same row logic: top half for r in range(rows), bottom half for r in range(rows - 2, -1, -1) — or extract a print_row(r) function to DRY both passes.
It closes the alphabet pattern series by stacking Program 33’s top half with a mirrored bottom half — the same two-loop diamond pattern used in number diamonds, hollow pyramids, and symmetric ASCII art. After this, continue to Python Number Pattern Programs.
" " * (rows - 1 - r) — row 0 gets rows - 1 spaces; bottom row gets none.
for r in range(rows): — identical row rule to Program 33.
for r in range(rows - 2, -1, -1): — mirror without repeating the widest row.
2*rows - 1 output lines for half height rows — widest row printed once.
In short: set base = ord('A'), print top half with range(rows), bottom half with range(rows - 2, -1, -1), using the same row rule — leading spaces, letter, optional gap and mirror — on every row.
Given a positive integer rows (half height), print a centered alphabet diamond of 2*rows - 1 lines. Row r prints (rows - 1 - r) leading spaces, then letter chr(ord('A') + r). For r > 0, print (2*r - 1) gap spaces and the same letter again. Top half: r = 0 .. rows-1. Bottom half: r = rows-2 .. 0.
# Half height rows = 5 (9 output lines)
A
B B
C C
D D
E E
D D
C C
B B
A | Item | Type | Description |
|---|---|---|
rows | int | Half height — apex to widest row (row letter runs A through the rows-th letter). Clamp to 1–26 for A–Z demos. |
| Printed output | text | Full alphabet diamond: 2*rows - 1 lines — widening rows up, then mirrored down without duplicating the widest row. |
base = ord('A')
for r from 0 to rows-1: # top half
print row(r)
for r from rows-2 down to 0: # bottom half
print row(r)
row(r):
print (rows-1-r) leading spaces
ch = chr(base + r)
print ch
if r > 0: print (2*r-1) gap spaces and ch
print newline | Approach | Idea | Best for |
|---|---|---|
| Two loops (inline row logic) | Top range(rows), bottom range(rows-2,-1,-1) with duplicated print steps | Learning how diamond halves connect |
print_row(r) function | Extract shared row logic; call from both loops | Cleaner code and easier testing |
| Program 33 contrast | See Program 33 (top half only) | Understand what the diamond adds — the bottom mirror loop |
| Goal | Pattern |
|---|---|
| Leading spaces | print(" " * (rows - 1 - r), end="") |
| Top half loop | for r in range(rows): |
| Bottom half loop | for r in range(rows - 2, -1, -1): |
| Total output lines | 2 * rows - 1 |
| Row letter | ch = chr(base + r) |
| Gap spaces (r > 0) | print(" " * (2 * r - 1), end="") |
| Row 0 guard | if r > 0: before gap and mirror |
| print_row helper | def print_row(r): ... called from both loops |
Three ways to think about the diamond — the top grows, the bottom mirrors, and a helper DRYs both.
range(rows)
r = 0 .. rows-1Identical to Program 33 — widening rows from A to the widest letter.
range(rows-2, -1, -1)
r = rows-2 .. 0Mirrors rows downward — starts at rows - 2 so the widest row is not printed twice.
def print_row(r):
same row logicExtract shared logic — leading spaces, letter, gap, mirror — and call from both loops.
range(rows-1, -1, -1)
duplicates widestStarting bottom at rows - 1 prints the widest row twice — use rows - 2 instead.
Reach for alphabet diamonds when closing Program 33’s triangle into a full symmetric shape — the capstone of the alphabet pattern series.
Program 33 prints the top half only. This program adds the bottom mirror loop to close the diamond.
Classic grow-then-shrink structure reused in number diamonds, star diamonds, and hollow pyramids.
Last alphabet pattern program — next section is Python Number Pattern Programs.
Extract shared row logic into a function — both halves call the same helper.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one program that combines Program 33’s widening rows with a mirrored bottom half — the same two-loop diamond pattern used in number patterns, hollow pyramids, and symmetric ASCII art throughout the series.
Choose half height between 1 and 26 and draw the full alphabet diamond in the browser.
Three complete Python programs — fixed five-row half height with two loops, console input with the same logic, and a print_row(r) helper to DRY both halves. Click View Output to reveal sample console results.
Print a full alphabet diamond with half height 5 — top half then bottom mirror.
rows = 5 (half height)Hard-coded half height — ideal for first demos and screenshots.
rows = 5
rows = max(1, min(rows, 26))
base = ord('A')
# Top half: r = 0 .. rows-1
for r in range(rows):
print(" " * (rows - 1 - r), end="")
ch = chr(base + r)
print(ch, end="")
if r > 0:
print(" " * (2 * r - 1), end="")
print(ch, end="")
print()
# Bottom half: mirror without repeating the widest row
for r in range(rows - 2, -1, -1):
print(" " * (rows - 1 - r), end="")
ch = chr(base + r)
print(ch, end="")
if r > 0:
print(" " * (2 * r - 1), end="")
print(ch, end="")
print() The first loop walks r from 0 to 4 — identical to Program 33. The second loop walks r from 3 down to 0, reusing the same row logic without printing the widest row (E E) again. Total output: 2*5 - 1 = 9 lines.
Let the user choose half height at runtime.
Read half height and clamp to 1–26. Wrap int(input()) in try/except ValueError in real apps.
rows = int(input("Enter number of rows (half height, max 26): "))
rows = max(1, min(rows, 26))
base = ord('A')
for r in range(rows):
print(" " * (rows - 1 - r), end="")
ch = chr(base + r)
print(ch, end="")
if r > 0:
print(" " * (2 * r - 1), end="")
print(ch, end="")
print()
for r in range(rows - 2, -1, -1):
print(" " * (rows - 1 - r), end="")
ch = chr(base + r)
print(ch, end="")
if r > 0:
print(" " * (2 * r - 1), end="")
print(ch, end="")
print() Same diamond core as Example 1; only half height comes from input. Three half-height rows produce 5 output lines: top 3 widening rows plus bottom 2 mirrored rows (starting at r = 1).
Extract shared row logic into a function — both loops call the same helper.
print_row(r) Function VariantDRY the two loops by extracting identical row logic into one function.
rows = 5
rows = max(1, min(rows, 26))
base = ord('A')
def print_row(r):
print(" " * (rows - 1 - r), end="")
ch = chr(base + r)
print(ch, end="")
if r > 0:
print(" " * (2 * r - 1), end="")
print(ch, end="")
print()
for r in range(rows):
print_row(r)
for r in range(rows - 2, -1, -1):
print_row(r) print_row(r) encapsulates leading spaces, letter, gap, and mirror — both loops simply call it with different r ranges. Produces identical output to Examples 1 and 2, but easier to test and maintain.
Clamp rows (half height), then set base = ord('A') for the alphabet starting point.
for r in range(rows - 2, -1, -1): — mirror rows without repeating the widest line.
Each row: leading spaces, letter, if r > 0 gap and mirror — extract as print_row(r) to DRY both loops.
2*rows - 1 output lines for half height rows — O(n²) time, O(1) extra memory (loop version).
rows = 5 (half height)Trace each value of r through top and bottom phases — top r = 0..4 matches Program 33; bottom starts at r = 3, 2, 1, 0.
| phase | r | letter | full row |
|---|---|---|---|
| top | 0 | A | A |
| top | 1 | B | B B |
| top | 2 | C | C C |
| top | 3 | D | D D |
| top | 4 | E | E E |
| bottom | 3 | D | D D |
| bottom | 2 | C | C C |
| bottom | 1 | B | B B |
| bottom | 0 | A | A |
Highlight: top r = 0..4 is identical to Program 33. Bottom starts at r = 3 (rows - 2), not r = 4 — starting at rows - 1 would duplicate the widest row E E. Total: 9 lines = 2*5 - 1.
Where alphabet diamonds show up — closing the alphabet pattern series before number patterns.
Program 33 is the top half only. This program adds the bottom mirror to close the diamond.
Example: run Program 33 output, then append rows for r = rows-2 .. 0.
Last program in the alphabet pattern series — next up is Python Number Pattern Programs.
Example: compare this diamond with number diamond patterns in the next section.
Extract shared row logic — both halves call the same function with different r ranges.
Example: test print_row(2) in isolation before wiring both loops.
Bottom loop must start at rows - 2, not rows - 1.
Example: for rows=5, bottom starts at r=3 — skipping r=4 prevents double E E.
2*rows - 1 lines with O(n) chars each — O(n²) total.
Example: half height 5 → 9 output lines, not 10.
Classic two-loop diamond question — explain why bottom starts at rows-2.
Example: explain half height vs total lines without running code.
Pro Tip: say “top half Program 33, bottom half rows-2 down to 0” before coding — that story prevents duplicating the widest row.
Why this pattern earns a spot as the alphabet pattern series finale.
Top half is Program 33; bottom half completes the symmetric diamond.
Classic grow-then-shrink structure reused across number and star patterns.
Function extraction keeps both halves readable and testable.
Streaming output needs no storage beyond loop counters.
Pro Tip: when bottom loop starts at rows - 1, you get two widest rows — start at rows - 2 instead.
Small habits that keep alphabet diamond code clean.
range(rows - 2, -1, -1) — never rows - 1 or the widest row prints twice.
Both loops share identical logic — a helper prevents copy-paste bugs.
rows = max(1, min(rows, 26)) keeps demos inside A–Z.
if r > 0: must wrap gap and mirror — never print a second A on row 0.
Trace 5 output lines: top A, B B, C C plus bottom B B, A.
Pro Tip: if gaps look too narrow, check the formula — it should be 2*r - 1, not 2*r.
Mistakes that commonly break alphabet diamonds.
Using range(rows - 1, -1, -1) duplicates the widest row — you get two middle lines.
→ Start bottom at rows - 2: for r in range(rows - 2, -1, -1):
Forgetting if r > 0 prints A A on row 0 — two letters at the apex.
→ Wrap gap and mirror in if r > 0: so row 0 prints only one A.
Using 2*r instead of 2*r - 1 makes gaps one space too wide starting at row 1.
→ Use 2*r - 1 for the gap — row 1 needs 1 space, row 4 needs 7.
Using r lead spaces or rows - r misaligns the triangle — rows lean or over-indent.
→ Use rows - 1 - r leading spaces so row 0 gets the most padding.
Expecting 2*rows output lines instead of 2*rows - 1 — the widest row appears once.
→ Half height rows=5 prints 9 lines, not 10.
Check these inputs before calling the solution done.
Output is just A — one line diamond; bottom loop range(-1, -1, -1) is empty.
Treat as invalid; re-prompt instead of silent empty output.
26 half height with letter Z at widest row — 51 total output lines.
Clamp to 26 or define a wrap/error policy before printing.
Use try/except ValueError before clamping rows.
Same loops work with base = ord('a') and lowercase output.
Try these variations to lock in the pattern.
print_row(r) from Example 3rows produces 2*rows - 1 output lines — widest row printed once.range(rows - 2, -1, -1) — starting at rows - 1 duplicates the widest row.print_row(r) is equivalent to inline row logic — use whichever fits your lesson.Quick Takeaway: top half range(rows), bottom half range(rows - 2, -1, -1), same row rule on every line — that is the whole alphabet diamond.
| Program | Time | Extra space |
|---|---|---|
| Two loops inline (Examples 1–2) | O(rows²) | O(1) |
| print_row function (Example 3) | O(rows²) | O(1) — function call overhead only |
The alphabet diamond combines Program 33’s widening top half with a mirrored bottom half — two loops, one row rule, 2*rows - 1 total lines. Master the inline two-loop version, then try the print_row(r) helper for cleaner code.
This closes the alphabet pattern series. Practice the three examples above, then continue to Python Number Pattern Programs.
Top half range(rows), bottom half range(rows - 2, -1, -1), guard row 0 with if r > 0, clamp rows to 26, and compare with Program 33 (widening triangle).
base = ord('A'), clamp half height rows to 1–26for r in range(rows): with Program 33 row logicfor r in range(rows - 2, -1, -1):if r > 0: gap 2*r-1 and mirror chprint_row(r) to DRY both loopsrows - 1 — duplicates widest row2*rows - 1ord('A')2*r for gap — gaps one space too widePrint the full diamond the beginner-friendly way — last program in the alphabet pattern series.
range(rows)
Growrange(rows-2, -1, -1)
Shrink2*rows - 1
CountDRY both loops
CodeO(n²) time
AnalysisThe top half uses r = 0 .. rows-1 with the same row rule as Program 33. The bottom half reuses that logic for r = rows-2 .. 0 so the widest row is not printed twice. Total output lines: 2*rows - 1.
You’ve completed the alphabet pattern series — next up: number patterns with the same diamond and pyramid ideas.
12 people found this page helpful