Python Reverse Alphabet Triangle Pattern (Decreasing)

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

What Is This Pattern?

A reverse alphabet decreasing triangle prints each row backward down to A, while the starting letter moves one step earlier each row — so the left edge slides inward.

Remember
Rule: for start letter i from last down to A,
      print i down through A

EDCBA
DCBA
CBA
BA
A         ← 5 rows (every row ends at A)

Same widths as Program 6 (5, 4, 3, 2, 1), but Program 6 prints forward to a fixed end (ABCDE, BCDE, …). Here both loops decrement. Compare with Program 8, which keeps E fixed on the left and shortens the tail.

How to Solve It

Two ways to emit the same shape — start with nested ord/chr loops, then optionally reverse a prefix once and slice.

MethodIdeaBest for
Nested ord/chr loopsOuter = lowering start; inner = start..A downwardLearning, interviews, exams
Reverse + sliceBuild EDCBA… once, drop one left letter each rowShorter demos once loops click

Pseudocode

Pseudocode
for start from lastLetter down to 'A':
    for ch from start down to 'A':
        print ch (no newline)
    print newline

Cheat sheet

GoalPattern
Lower start letterfor i in range(top, ord('A') - 1, -1):
Print i..A reversefor j in range(i, ord('A') - 1, -1): print(chr(j), end="")
End the rowprint()
Top letter from rowstop = ord('A') + rows - 1
One-line row shortcutReverse the A…top prefix, then top[i:]
Forward twinProgram 6 — print i..end upward

Printing Letters vs Starting a New Line

APIEffectUse for
print(ch, end="")Stays on the same lineEach letter
print()Ends the current lineAfter the inner loop

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

Live Preview

Change the row count and the reverse decreasing triangle updates instantly — capped at 26 letters (A–Z).

Whole numbers from 1 to 26. Tap a chip or type a value — the preview redraws as you go.

Live result 5 rows · 15 letters
EDCBA
DCBA
CBA
BA
A

Worked Walkthrough — rows = 4

Trace each outer-loop start letter as i counts down from ord('D') to ord('A').

Start iInner jPrinted rowLetters
'D'D..ADCBA4
'C'C..ACBA3
'B'B..ABA2
'A'A..AA1

Total letter prints: 4 + 3 + 2 + 1 = 10 = 4×5/2 — same triangular count as Programs 1 and 6.

Python Programs

Three complete programs: fixed top letter, input(), and a reverse-slice shortcut. Use View Output to reveal sample results.

Example 1 — Fixed from 'E' down to 'A'

Hard-coded top letter — both loops decrement; every row ends at A.

Python
for i in range(ord('E'), ord('A') - 1, -1):
    for j in range(i, ord('A') - 1, -1):
        print(chr(j), end="")
    print()

How It Works

1. Outer loop picks the start letter. i runs from ord('E') down to ord('A') — longest row first.

2. Inner loop walks down to A. For each start, j runs from i down to ord('A'), so the row is i..A in reverse.

3. Print letters, then break the line. print(chr(j), end="") stays on the row; bare print() after the inner loop starts the next (shorter) row.

When i is 'E' you get EDCBA; when i is 'A' you get A.

Example 2 — User Input Version

Read the row count at runtime. Prefer try/except ValueError and clamp to 26 (shown in the tip below).

Python
raw = input("Enter the number of rows: ").strip()
rows = int(raw)
top = ord('A') + rows - 1

for i in range(top, ord('A') - 1, -1):
    for j in range(i, ord('A') - 1, -1):
        print(chr(j), end="")
    print()

How It Works

1. Prompt and read. Ask for a row count, then convert the line to an int.

2. Map rows to a top letter. top = ord('A') + rows - 1 — for rows = 4, top is ord('D').

3. Same reverse-shrink core. Only the source of top changes — the print logic matches Example 1.

4. Safer input tip. Bare int(...) raises on letters. Prefer:

Safer input
try:
    rows = int(input("Enter the number of rows: ").strip())
except ValueError:
    print("Enter a whole number from 1 to 26.")
else:
    if rows < 1 or rows > 26:
        print("Enter a whole number from 1 to 26.")
    else:
        # draw pattern here
        pass

Example 3 — Reverse + slice

Build the first reverse row once, then drop one left letter each time — same shape, no nested letter loop.

Python
rows = 5
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
top = letters[:rows][::-1]

for i in range(rows):
    print(top[i:])

How It Works

1. Take and reverse the prefix. ABCDE reversed becomes EDCBA — the first printed row.

2. Slice from index i. top[0:] is the full row; top[1:] drops E; and so on down to A.

3. Learn loops first. Use Examples 1–2 when you need to show nested bounds; treat this as a polish shortcut afterward.

Edge Cases & Pitfalls

Check these before calling the solution done.

step +1

Program 6 by mistake

If the inner loop increments instead of decrements, you print forward suffixes. Use range(i, ord('A') - 1, -1).

Fixed start

Program 8 shape

If the outer loop stays on 'E' and only shortens the stop, you get EDCBA, EDCB, … Advance (lower) the start with a countdown outer range.

print early

Column of letters

If bare print() (or default print(chr(j))) is inside the inner loop, each letter lands on its own line. Use end="" for letters; call print() only after the inner loop.

rows > 26

Past Z

ord('A') + rows - 1 leaves A–Z when rows > 26. Clamp or reject in interactive programs.

rows = 1

Single A

Output is just A — start and end coincide. A good sanity check.

Bad input

Catch ValueError

Bare int(input()) raises on letters — wrap in try/except ValueError and require 1–26.

Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–2)O(rows²)O(1)
Reverse + slice (Example 3)O(rows²)O(rows) for the reversed prefix and temporary row strings

Total letters = n + (n - 1) + … + 1 = n(n + 1)/2 — quadratic in n. Same totals as Programs 1 and 6.

Key Takeaways

  • Rule: lower start letter i; print i down through A each row.
  • vs Program 6: same widths — here letters run backward to A; there they run forward to a fixed end.
  • Break the row: call bare print() only after the inner loop.
  • Complexity: O(n²) time from the triangular letter count; O(1) extra space for nested loops.

One line: for i from the top letter down to 'A', print i down through A, then print().

Frequently Asked Questions

The outer loop picks the starting letter (E, then D, then C…). The inner loop prints from that start down to A. Each row drops the previous leftmost letter and becomes shorter.
The outer loop decreases the starting letter each row, and the inner loop decreases letters within that row down to A. That matches the reverse-alphabet output.
Because the inner range includes A: range(start, ord('A') - 1, -1). The stop is one below A so A is printed.
Program 6 prints forward suffixes ending at E (ABCDE, BCDE, …). This pattern prints reverse runs ending at A (EDCBA, DCBA, …). Same shrinking widths; opposite letter direction.
Program 8 always starts each row at E and shortens the tail (EDCBA, EDCB, EDC). Program 7 changes the first letter each row (E, then D, then C…).
print(..., end="") stays on the same line. print() ends the current line. Letters use end=""; the row break uses print() after the inner loop.
O(n²) for n rows, because total printed characters are n(n+1)/2.
Use try/except ValueError around int(input()) and clamp rows between 1 and 26 so bad input does not raise or walk past Z.

Did you know?

Both loops run backward: the outer loop lowers the start letter; the inner loop prints down to A. For 5 rows: EDCBA, DCBA, CBA, BA, A. Same widths as Program 6, opposite letter direction.

Next: Reverse Fixed Start

Keep E on the left and shorten the reverse tail each row.

Program 8 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