Reverse Alphabet Right-Angled Triangle Pattern in Python

Beginner
⏱️ 8 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Nested Loops

What You’ll Learn

Print a reverse alphabet right-angled triangle: each row has one more character than the previous, and letters go from a top letter down toward AE, ED, EDC, EDCB, EDCBA. Same geometry as Program 1, but descending along the alphabet. Includes a live preview, worked Python examples, edge cases, and complexity.

Shape Rule

Growing reverse rows

Row i prints i letters from top down.

Outer Loop

Row length

for i in range(1, rows + 1): picks how many letters each row prints.

Inner Loop

Always from top

range(top, top - i, -1) prints descending codes from top.

ord() / chr()

Letter codes

top = ord('A') + rows - 1 then chr(code) for output.

Live Preview

1–10 rows

Pick a row count and draw the reverse triangle instantly in the browser.

O(n²)

Complexity

Triangular letter count: n(n+1)/2 prints.

Introduction

A reverse alphabet right-angled triangle grows like Program 1, but every row starts at a fixed top letter and counts downward until a row-specific end letter.

In Python you solve it with nested for loops and range(..., -1): the outer loop picks the row length, the inner loop prints letter codes from top down, then print() moves to the next line.

Why it matters?

It locks in reverse iteration with range step -1 — the same skill used in reverse triangles, diagonals, and mirrored alphabet labs.

Key Highlights

Growing Rows

1, 2, 3, … letters per row.

Always From Top

Inner loop restarts at the top letter.

Descending Letters

range(top, top - i, -1) counts down.

Mirror of Program 1

Same triangle; opposite letter direction.

In short: for each row i from 1 to rows, print top..top-i+1 with print(chr(code), end=""), then call print().

📝 Problem & Approach

Given a positive integer rows, print a left-aligned reverse alphabet right-angled triangle of letters with rows lines.

Python
# First 5 rows (conceptual shape)
# E
# ED
# EDC
# EDCB
# EDCBA

Inputs & Outputs

ItemTypeDescription
rowsintNumber of triangle lines to print (typically ≥ 1).
topint (code)Top letter code: ord('A') + rows - 1.
Printed outputtextGrowing reverse prefixes from top down to A on the last row.

Minimal workflow

Pseudocode
top = ord('A') + rows - 1
for i from 1 to rows:
    for code from top down to top - i + 1:
        print letter (no newline)
    print newline

Approach comparison

ApproachIdeaBest for
range(..., -1)Outer row length + inner descending codesLearning and interviews
Char outer loopWalk end letter from top down to AMatching classic E…EDCBA samples

⚡ Quick Reference

GoalPattern
Top lettertop = ord('A') + rows - 1
Walk each rowfor i in range(1, rows + 1):
Print descendingfor code in range(top, top - i, -1): print(chr(code), end="")
End the rowprint()
Forward triangleSee Program 1
LowercaseUse ord('a') as the base instead of ord('A')

📋 print end= vs print() vs Direction

Same triangle idea as Program 1 — only letter direction changes.

print(..., end="")
letter

Prints each descending letter on the current row

print()
break

Ends the row after top..end finishes

Program 2
top..down

Inner loop uses range(..., -1)

Program 1
A..end

Inner loop counts up from A

Context

When This Pattern Shows Up

Reach for this when teaching reverse character loops on a growing triangle.

  1. Right after Program 1

    Keep the triangle; flip letter direction to descending.

  2. Reverse range drills

    Practice range(top, stop, -1) and stopping before top - i.

  3. Before Program 3

    Next you change only the starting letter while counting forward.

  4. Top-letter math

    Practice top = ord('A') + rows - 1 for any height.

  5. Not a UI layout tool

    This is a console teaching pattern — not how you build modern app screens.

Key benefit: one bound change (range(..., -1)) turns a forward triangle into a reverse one.

🔮 Live Preview

Choose between 1 and 10 rows and draw the reverse alphabet triangle in the browser.

Try 5 (classic E…EDCBA) or 4 (D…DCBA). Max 10 keeps the preview readable.

Live result
Press "Draw pattern".

Examples Gallery

Three complete Python programs — fixed row count, CLI input, and a spaced-letter variant. Click View Output to reveal sample console results.

📚 Getting Started

Print five reverse rows with nested loops and range(..., -1).

Example 1 — Fixed rows = 5

Hard-coded height — ideal for first demos and screenshots.

Python
rows = 5
top = ord('A') + rows - 1

for i in range(1, rows + 1):
    for code in range(top, top - i, -1):
        print(chr(code), end="")
    print()

How It Works

When i = 1, the inner loop prints E. When i = 3, it prints EDC, and so on through five letters on the last row. print() after the inner loop starts the next row.

📈 Practical Variant

Let the user choose the height at runtime.

Example 2 — User Input Version

Read the row count with input() and clamp with max(1, min(rows, 26)) (wrap in try/except ValueError in real apps).

Python
rows = int(input("Enter the number of rows: "))
rows = max(1, min(rows, 26))
top = ord('A') + rows - 1

for i in range(1, rows + 1):
    for code in range(top, top - i, -1):
        print(chr(code), end="")
    print()

How It Works

Same ord/chr core as Example 1; only the source of rows changes. For 4 rows, top becomes ord('D'). Non-numeric input raises ValueError with bare int(input()) — use try/except for safer labs.

⚡ Readability Variant

Same reverse triangle with spaces between letters.

Example 3 — Spaced Letters

Print a trailing space after each letter so columns are easier to scan.

Python
rows = 5
top = ord('A') + rows - 1

for i in range(1, rows + 1):
    for code in range(top, top - i, -1):
        print(chr(code) + " ", end="")
    print()

How It Works

Loop bounds are unchanged — only the printed unit becomes chr(code) + " ". Trim trailing spaces later if you need a compact line.

🧠 How the Algorithm Prints Rows

1

Set up

Set rows (fixed or from input()). Compute top = ord('A') + rows - 1.

Setup
2

Outer loop (rows)

for i in range(1, rows + 1): selects how many letters print on the current line.

Row
3

Inner loop (descending)

for code in range(top, top - i, -1): prints each letter with print(chr(code), end="").

Letters
4

New line

print() ends the row so the next outer iteration starts fresh.

Break
=

Reverse letter triangle complete

Total letters: 1+2+…+n = n(n+1)/2O(n²) time, O(1) extra memory.

🔎 Worked Walkthrough — rows = 5

Trace each outer value of i and the descending codes the inner loop prints from top = E.

Row iInner rangePrinted rowLetters this row
1range(E, D, -1)E1
2range(E, C, -1)ED2
3range(E, B, -1)EDC3
4range(E, A, -1)EDCB4
5range(E, top-5, -1)EDCBA5

*range stops before the end value, so top - 5 is below A and all five letters print. Total letter prints: 1 + 2 + 3 + 4 + 5 = 15 = 5×6/2.

Use Cases

Where this reverse triangle (and its descending loops) shows up beyond the homework prompt.

1. Direction Practice

Clearest alphabet demo of counting letters downward with range(..., -1).

Example: flip bounds to Program 1 and compare.

2. Pair with Program 1

Same triangle geometry — forward vs reverse fill.

Example: print both side by side for n = 5.

3. Top-Letter Labs

Practice computing top from a row count.

Example: rows 1..10 map to A..J.

4. Spaced Output

Add separators without changing loop structure (Example 3).

Example: print chr(code) + " " for readable columns.

5. Complexity Intuition

Triangular sums make O(n²) easy to see.

Example: 5 rows print 15 letters total.

6. Input Validation Labs

Pair the pattern with try/except ValueError and clamp to 26.

Example: reject rows > 26 or clamp it.

Pro Tip: say “always start at top, print down for i letters” before coding — that story prevents wrong inner bounds.

Advantages

Why this pattern earns a spot right after the forward alphabet triangle.

  1. 1. Instant Visual Feedback

    Wrong direction or bounds show up immediately as a non-reverse triangle.

  2. 2. Tiny Change from Program 1

    Same structure; only loop direction and range step flip.

  3. 3. Teaches Reverse range()

    range(top, top - i, -1) is reusable in many Python patterns.

  4. 4. O(1) Extra Memory

    Streaming output needs no storage beyond loop counters.

Pro Tip: master Program 1 first; treat this page as the same story with arrows reversed.

Usage Tips

Small habits that keep reverse-triangle code clean.

  1. 1. Restart Inner at Top

    Every row starts from the same top letter; only the count changes with i.

  2. 2. Use range(top, top - i, -1)

    That triple is what produces E, ED, EDC, …

  3. 3. Wrap int(input()) in try/except

    Avoid crashes when the user types letters instead of a number.

  4. 4. Cap at 26 Rows

    Beyond Z you need a wrap/stop policy for top.

  5. 5. Dry-Run Row 3

    Trace EDC on paper before coding larger n.

Pro Tip: if every row starts with a different letter and runs forward to E, you wrote Program 3 — not this pattern.

Common Pitfalls

Mistakes that commonly break reverse alphabet triangles.

  1. 1. Using Forward Inner Bounds

    range(start, start + i) prints Program 1 instead.

    → Use range(top, top - i, -1).

  2. 2. Forgetting Step -1

    range(top, top - i) with default step +1 produces an empty range.

    → Always pass -1 as the third argument.

  3. 3. print() Inside the Inner Loop

    Each letter lands on its own line — you get a column, not a triangle.

    → Use print(..., end="") for letters; print() only after the inner loop.

  4. 4. Blind int(input())

    Non-numeric input raises ValueError with bare int(input()).

    → Wrap in try/except ValueError and validate range.

  5. 5. Overflowing Z

    Large rows makes top walk past Z.

    → Cap input at 26 or define a wrap policy.

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single letter

Output is just A on one line.

rows = 5

Classic sample

Through EDCBA.

rows = 4

Shorter triangle

Top is D → DDCBA.

rows > 26

Past Z

Reject, clamp, or wrap — decide explicitly.

Bad input

Non-numeric input

int(input()) raises ValueError — validate first.

Case

Lowercase

Same loops with ord('a') as the base.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Flip to forward

2. Add spaces

  • Print chr(code) + " " (Example 3)
  • Keep the same loop bounds

3. Change only the start

4. Star triangle twin

Notes

  • Same top every row. Only how many letters print changes with i.
  • Total letters for n rows is the triangular number n(n+1)/2.
  • Compute top = ord('A') + rows - 1 to generalize any height.
  • This is the descending mirror of Program 1’s forward triangle.

Quick Takeaway: start every row at the top letter, print down for i letters, then break the line — that is the whole triangle.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Fixed / input (Examples 1–2)O(rows²)O(1)
Spaced letters (Example 3)O(rows²)O(1)

Row k prints k letters; summing 1..n gives n(n+1)/2 character writes.

Wrap Up

🎉 Conclusion

The reverse alphabet right-angled triangle is a small nested-loop exercise with lasting payoff: fixed top letter, descending inner walk with range(..., -1), and growing row length. Master the classic E…EDCBA sample, then try user input and optional spacing.

Practice the three examples above, then continue to Program 3’s triangle where each row starts one letter earlier but still runs forward.

Compute a top letter, print top..top-i+1 on each row, and break only after the inner loop finishes.

💡 Best Practices

✅ Do

  • Restart the inner loop at top every row
  • Use range(top, top - i, -1) for descending output
  • Compute top = ord('A') + rows - 1
  • Wrap int(input()) in try/except ValueError and cap at 26
  • State O(n²) when asked about complexity

❌ Don’t

  • Use forward range(start, start + i) bounds for this pattern
  • Forget the -1 step in the inner range
  • Call print() inside the inner letter loop
  • Let rows exceed 26 without a policy
  • Confuse this with Program 3’s changing start letter

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print the reverse alphabet right-angled triangle the beginner-friendly way.

5
Core concepts
T 02

Top

Inner always starts here

Code
-1 03

range step

Counts down to top-i

Code
04

print()

Ends each row

I/O
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

The outer loop picks row length i from 1 to rows. The inner loop uses range(top, top - i, -1) to print top down through i letters — so row 1 is E, row 2 is ED, and so on.
The inner loop always starts at top (E when rows = 5). Only how many letters print changes with i — that is what grows the reverse triangle.
print(chr(code), end="") stays on the same line. print() ends the current row. Letters use end=""; the row break uses print() after the inner loop.
Use Program 1: loop upward from A with range(start, start + i). This page is the descending mirror of that forward triangle.
O(n²) where n is the number of rows. Total printed characters equal 1+2+…+n = n(n+1)/2.
Use try/except ValueError around int(input()), then clamp rows with max(1, min(rows, 26)) so bad input does not walk past Z.
The step -1 counts down. range stops before top - i, so you get exactly i values: top, top-1, …, top-i+1.
Yes. Use ord('a') as the base: top = ord('a') + rows - 1, then keep the same nested range(..., -1) loops.

Did you Know? 🔊

Row i prints i letters from the top letter down. For 5 rows the output is E, ED, EDC, EDCB, EDCBA — the descending mirror of Program 1. Total letters = n(n+1)/2.

Continue to Alphabet Pattern 3

Next up: each row starts one letter earlier, but letters still run forward to the top.

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