An alphabet diamond widens from a centered A to a middle letter, then narrows back to A — using Program 33’s hollow row rule twice.
Remember
Top: r = 0 .. rows-1 (Program 33)
Bottom: r = rows-2 .. 0 (skip widest)
A
B B
C C
D D
E E ← middle once
D D
C C
B B
A ← half height 5 → 9 lines
Total lines are 2*rows - 1. This is the last alphabet-pattern program — next up: number patterns.
Approach
How to Solve It
Print rows 0..rows-1, then reuse the same row printer for rows-2..0.
Method
Idea
Best for
Two outer loops
Top range(rows), bottom range(rows-2, -1, -1)
Learning, interviews, exams
print_row helper
Own pads/letter/gap once; both loops call it
Cleaner demos; reuse from Program 33
Pseudocode
Pseudocode
print_row(r):
print (rows - 1 - r) spaces
ch = 'A' + r
print ch
if r > 0:
print (2 * r - 1) spaces
print ch
print newline
for r from 0 to rows - 1: // top
print_row(r)
for r from rows - 2 down to 0: // bottom (skip widest)
print_row(r)
One line: print rows 0..n-1 then n-2..0 with Program 33’s pads + letter + gap rule.
Frequently Asked Questions
An alphabet diamond prints widening mirrored letter rows from A up to the middle letter, then mirrors back down to A without repeating the widest row. For half height rows=5 you get 9 output lines: A, B B, ... E E, ... A.
The top half loop already printed the widest row at r=rows-1. Starting the bottom at rows-2 avoids duplicating that middle line — same idea as starting a descend loop at peak-1 in palindrome pyramids.
Program 33 prints only the top half (widening alphabet triangle). Program 34 runs the same print_row logic twice: range(rows) for the top, then range(rows-2, -1, -1) for the bottom mirror.
rows is half height (apex to widest row). Total printed lines are 2*rows - 1 because the widest row appears once. For rows=5 you print 9 lines, not 10.
Both halves use identical row logic — leading spaces, letter, optional gap, mirror letter. A print_row helper DRYs the code and makes the two-loop structure easier to read and test.
Each row letter is chr(ord('A') + r). With rows > 26 you would need characters beyond Z unless you define a wrap or error policy.
O(n²) where n is half height. About 2n-1 rows each print O(n) characters in the worst case; the total character count grows quadratically.
Use try/except ValueError around int(input()), then clamp rows between 1 and 26.
🤔
Did you know?
The 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.