Python Alphabet Square Pattern (Symmetric Decreasing)

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

What Is This Pattern?

A symmetric decreasing alphabet square is a layered square of letters: the outer border stays at the top letter, and each deeper row lowers the floor until the center is A.

Remember
Rule: cell = alpha[j] if j > i else alpha[i]
      left j = k..0, right j = 1..k (A once)

E E E E E E E E E
E D D D D D D D E
E D C C C C C D E
E D C B B B C D E
E D C B A B C D E     ← top = E (k = 4)

Width is always 2k + 1 (9 for A–E). Program 29 reuses this row rule and mirrors upward for a full diamond.

How to Solve It

For each floor i from top down to A, scan left then right with the same j > i cell rule.

MethodIdeaBest for
Inline ternaryalpha[j] if j > i else alpha[i] in both half loopsLearning the classic floor rule
Helper methodprint_cell(alpha, j, i) owns the rule onceClearer halves; reuse in Program 29

Pseudocode

Pseudocode
k = index of top letter (E → 4)
alpha = "A".."Z"
for i from k down to 0:          // row floor
    for j from k down to 0:      // left half
        print (j > i ? alpha[j] : alpha[i])
    for j from 1 to k:           // right half (skip 0)
        print (j > i ? alpha[j] : alpha[i])
    print newline

Cheat sheet

GoalPattern
Top indexk = ord("E") - ord("A")
Walk floorsfor i in range(k, -1, -1):
Left halffor j in range(k, -1, -1):
Right halffor j in range(1, k + 1): — start at 1
Floor rulealpha[j] if j > i else alpha[i]
Row width2 * k + 1
End the rowprint()

Printing Letters vs Starting a New Line

APIEffectUse for
print(ch, end=" ")Stays on the same rowEach cell on both halves
print()Ends the current rowAfter left + right halves

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

Live Preview

Change the size (top letter) and the layered square updates instantly — including width and floor letter on the last row.

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

Live result 5 letters · top E · width 9
E E E E E E E E E
E D D D D D D D E
E D C C C C C D E
E D C B B B C D E
E D C B A B C D E

Worked Walkthrough — top = C (k = 2)

Width is 2×2 + 1 = 5. Trace the floor and a sample interior vs border cell.

Floor iBorder rulePrinted row
2 (C)All cells ≥ C → all CC C C C C
1 (B)j > 1 → C; else BC B B B C
0 (A)j > 0 → C/B; else AC B A B C

Each of k+1 rows prints 2k+1 cells → O(n²) for n = k+1 letters.

Python Programs

Three complete programs: fixed A–E, top-letter input(), and a helper-method style. Use View Output for sample results.

Example 1 — Fixed A–E

Two symmetric scans per row with the same j > i check.

Python
k = ord("E") - ord("A")
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i in range(k, -1, -1):
    for j in range(k, -1, -1):
        print(alpha[j] if j > i else alpha[i], end=" ")

    for j in range(1, k + 1):
        print(alpha[j] if j > i else alpha[i], end=" ")

    print()

How It Works

1. Set the top index. k = 4 for E. Floors run from 4 down to 0.

2. Left half. Scan j = k..0. When j > i, print the border letter alpha[j]; otherwise print the floor alpha[i].

3. Right half. Scan j = 1..k with the same rule. Starting at 1 avoids a second center A.

When i = 2 (floor C): borders stay E/D where j > 2; interior cells print C.

Example 2 — Top Letter Input

Works for A..top with the same symmetric square. Validate a single A–Z character.

Python
raw = input("Enter top letter (like E): ").strip().upper()
if len(raw) != 1 or not ("A" <= raw <= "Z"):
    print("Please enter a single letter A-Z.")
    raise SystemExit(1)

k = ord(raw) - ord("A")
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i in range(k, -1, -1):
    for j in range(k, -1, -1):
        print(alpha[j] if j > i else alpha[i], end=" ")

    for j in range(1, k + 1):
        print(alpha[j] if j > i else alpha[i], end=" ")

    print()

How It Works

1. Prompt and validate. Strip, uppercase, and require a single A–Z letter.

2. Scale with k. k = ord(top) - ord("A") sets floors and both halves. Width becomes 2k + 1 (5 for top = C).

Example 3 — Helper Method

Often clearer: one method applies the floor rule so left and right loops stay thin.

Python
def print_cell(alpha, j, i):
    print(alpha[j] if j > i else alpha[i], end=" ")

k = ord("E") - ord("A")
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i in range(k, -1, -1):
    for j in range(k, -1, -1):
        print_cell(alpha, j, i)

    for j in range(1, k + 1):
        print_cell(alpha, j, i)

    print()

How It Works

1. One rule owner. print_cell owns the j > i choice once.

2. Thin halves. Left and right loops only decide which columns to visit — handy when you reuse the same row for Program 29.

Edge Cases & Pitfalls

Check these before calling the solution done.

double A

Right half starts at 0

Starting the right scan at j = 0 duplicates the center A. Keep range(1, k + 1).

wrong compare

j >= i vs j > i

Using >= changes which cells belong to the border. Stick with j > i.

ascend floors

Outer loop goes up

This sample descends from k to 0. Ascending floors is the second half of Program 29, not this square.

newline early

Bare print() inside halves

Use end=" " for cells; call bare print() only after both halves finish.

top = A

Single A

Output is just A (right half empty) — a good sanity check.

Bad input

Validate one letter

Reject empty strings and multi-character input before computing k.

Time and Space Complexity

ProgramTimeExtra space
Inline halves (Examples 1–2)O(n²)O(1) beyond the alphabet string
Helper method (Example 3)O(n²)O(1) beyond the alphabet string

There are n = k+1 rows and each prints 2k+1 cells, so total work is quadratic in the number of letters.

Key Takeaways

  • Rule: alpha[j] if j > i else alpha[i] builds borders and floors together.
  • Mirror: left k..0, right 1..k — center A once.
  • Width: every row has 2k + 1 cells (9 for A–E).
  • Next step: Program 29 reuses this row and mirrors upward for a diamond.

One line: for each floor i, print left k..0 and right 1..k with the j > i cell rule.

Frequently Asked Questions

It prints the border letters when the column index j is above the current row floor i; otherwise it prints i. This builds higher-letter borders with a flat interior.
The first loop scans from k down to 0 (E down to A). The second scans 1 up to k so the middle A is printed once and the row is mirrored.
For letters A..k, width is (k+1) + k = 2*k+1. For A..E (k=4), width is 9.
Pick a larger top letter (like H), set k = ord(top) - ord('A'), and keep the same loop structure.
O(n²) for n letters because there are n rows and each row prints O(n) cells.
Starting at 0 would print alpha[0] (A) again and duplicate the center. Starting at 1 (B) mirrors the left half cleanly.
Read a line, strip it, call .upper(), require a single A–Z character, and reject empty or multi-character input.
Program 29 reuses the same row logic while descending to A, then mirrors upward from B to E so you get a full reverse-centered diamond without duplicating the center row.

Did you know?

Fix k at the top letter (E). Outer loop i goes from k down to 0 (A). Left half scans j = k..0; right half scans j = 1..k so A appears once in the middle. Each position prints alpha[j] when j > i, otherwise prints alpha[i].

Next: Reverse Centered Alphabet Pyramid

Descend to A with this row rule, then ascend from B to E — a full diamond without a duplicated center.

Program 29 tutorial →

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