Python Diamond Alphabet Pattern

Beginner
7 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

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.

How to Solve It

Print rows 0..rows-1, then reuse the same row printer for rows-2..0.

MethodIdeaBest for
Two outer loopsTop range(rows), bottom range(rows-2, -1, -1)Learning, interviews, exams
print_row helperOwn pads/letter/gap once; both loops call itCleaner 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)

Cheat sheet

GoalPattern
Half heightrows = apex to widest (5 → peak E)
Total lines2 * rows - 1
Top halffor r in range(rows):
Bottom halffor r in range(rows - 2, -1, -1):
Row rulepads + letter; if r > 0: gap 2*r-1 + letter
Skip double middleBottom starts at rows - 2
End the rowprint()
Top onlySee Program 33

Printing Letters vs Starting a New Line

APIEffectUse for
print(..., end="")Stays on the same rowPads, letter, gap, mirror letter
print()Ends the current rowAfter the whole row is built

Print cells without a newline, then end the row once.

Live Preview

Change the half height and the full diamond updates instantly — including total line count.

Whole numbers from 1 to 10. Size 5 means middle letter E and 9 total lines. Tap a chip or type a value — the preview redraws as you go.

Live result half 5 · 9 lines
    A
   B B
  C   C
 D     D
E       E
 D     D
  C   C
   B B
    A

Worked Walkthrough — rows = 3

Top prints r = 0..2; bottom prints r = 1..0 (skips the widest C C).

PhaserPrinted row
Top0A
Top1B B
Top2C C
Bottom1B B
Bottom0A

About 2n-1 rows with O(n) work each → O(n²).

Python Programs

Three complete programs: fixed half height, input, and a print_row helper. Use View Output for sample results.

Example 1 — Fixed rows = 5

Top half like Program 33; bottom half mirrors without repeating the widest row.

Python
rows = 5
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: skip 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()

How It Works

1. Top half. r walks 0…4 — same pads + letter + gap rule as Program 33.

2. Bottom half. r walks 3…0 so E E is not printed twice.

3. Line count. Total lines = 2*5 - 1 = 9.

Example 2 — Half Height Input

Read half height and clamp to 1–26 so letters stay in A–Z.

Python
raw = input("Enter number of rows (half height, max 26): ").strip()
try:
    rows = int(raw)
except ValueError:
    print("Please enter a whole number.")
    raise SystemExit(1)

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()

How It Works

1. Validate half height. Parse an integer, then clamp to 1..26.

2. Same two phases. Half height 3 → 5 output lines (top 3 + bottom 2).

Example 3 — print_row Helper

Extract the shared row rule so both loops stay thin.

Python
rows = 5
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)

How It Works

1. One rule owner. print_row owns pads, letter, gap, and mirror.

2. Thin phases. The two loops only choose which r values to visit — handy if you already built Program 33’s row helper.

Edge Cases & Pitfalls

Check these before calling the solution done.

double middle

Bottom starts at rows - 1

Starting at the widest index reprints the middle row. Keep range(rows - 2, -1, -1).

open triangle

Missing bottom half

Forgetting the second loop leaves Program 33’s triangle. Add the descending phase.

wrong gap

2 * r instead of 2 * r - 1

Even gaps misalign both halves. Stick with odd gaps: 1, 3, 5, 7…

newline early

Bare print() mid-row

Use end="" for pads and letters; call bare print() only after the full row.

rows = 1

Single A

Top prints A; bottom range(-1, -1, -1) is empty — a good sanity check.

Bad input

Non-integer half height

Catch ValueError from int(...) before either loop.

Time and Space Complexity

ProgramTimeExtra space
Inline halves (Examples 1–2)O(n²)O(1)
print_row helper (Example 3)O(n²)O(1)

About 2n-1 rows with up to O(n) characters each → quadratic in half height n.

Key Takeaways

  • Reuse: Program 33’s row is the top half; add rows-2..0 to close the diamond.
  • Skip middle: bottom starts at rows - 2 so the widest row prints once.
  • Size: half height n → 2n - 1 lines (9 for n = 5).
  • Next step: move on to number pattern tutorials.

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.

Next: Number Pattern Programs

You finished the alphabet series — continue with nested-loop number patterns in Python.

Number patterns hub →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful