Inverted Repeating-Letter Alphabet Triangle in Python

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

What You’ll Learn

First row: five Es. Each following row is one character shorter and uses the next letter down: EEEEE, DDDD, CCC, BB, A. Compare with Program 10 (width grows) and worked Python examples, live preview, edge cases, and complexity.

Shape Rule

Wide first, then shrink

Row 1 prints EEEEE, then DDDD, down to a single A.

Outer Loop

Letter countdown

for i in range(ord('E'), ord('A') - 1, -1): picks the letter for each row.

Inner Loop

Width 5…1

for j in range(ord('A'), i + 1): shrinks as i falls — print chr(i), not the inner counter.

print end= vs print()

Same line / next line

Letters use print(..., end=""); end each row with print().

Live Preview

1–26 rows

Pick a row count and draw the inverted repeating triangle in the browser.

O(n²)

Complexity

Total letters = n(n+1)/2; extra memory stays O(1).

Introduction

An inverted repeating alphabet triangle starts wide and shrinks by one repeated letter on each new line, counting letters downward from the top of the alphabet range. With the right angle on the left, the console shows an upside-down staircase of identical letters per row.

In Python you usually solve it with two nested for loops: the outer loop picks the row letter (counting down), the inner loop prints that same letter fewer times each row, then print() moves to the next line.

Why it matters?

It shows that “inverted” often means flipping only the width bound — not inventing a new algorithm. Once outer letter vs inner count clicks, Program 10, 11, and 12 are one-line cousins.

Key Highlights

Widest First

Top row repeats the highest letter n times.

Width Shrinks

Rows go 5, 4, 3, …, 1 while letters go E→A.

Print Outer Letter

print(chr(i), end="") in the inner loop; print() after.

Invert of Program 10

Same letters — opposite width direction.

In short: for each letter i from top down to A, print i repeatedly (i - ord('A') + 1) times, then call print().

📝 Problem & Approach

Given a positive integer rows (or a fixed top letter like 'E'), print a left-aligned inverted triangle where each row repeats one letter and widths shrink from rows down to 1.

Python
# First 5 rows (conceptual shape)
# EEEEE
# DDDD
# CCC
# BB
# A

Inputs & Outputs

ItemTypeDescription
rowsintNumber of triangle lines (typically 1–26). Top letter = chr(ord('A') + rows - 1).
Printed outputtextLeft-aligned rows; letter ch is repeated code - base + 1 times.

Minimal workflow

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

Approach comparison

ApproachIdeaBest for
Nested char loopsOuter letter + inner A..i widthLearning and interviews
ch * repeatBuild a whole row in one callShorter production-style demos

⚡ Quick Reference

GoalPattern
Walk letters downwardfor i in range(ord('E'), ord('A') - 1, -1):
Shrink repeat countfor j in range(ord('A'), i + 1):
Print row letterprint(chr(i), end="") — not the inner counter
End the rowprint()
One-line row shortcutprint(ch * repeat)
Growing widthsSee Program 10 (E, DD, CCC, …)

📋 print end= vs print() vs *

Same triangle — different ways to emit characters.

print(..., end="")
same line

Prints a letter without moving to the next line

print()
new line

Ends the current row after all repeats are printed

ch * n
whole row

Builds n copies of ch at once — skip the inner loop

Learning tip
print chr(i)

Master printing the outer letter before the string shortcut

Context

When This Pattern Shows Up

Reach for this triangle when practicing inverted widths with repeating letters.

  1. After Program 10

    Flip only the width direction while keeping letter countdown.

  2. Bound-flip drills

    j <= i from A naturally shrinks as i falls.

  3. Char arithmetic practice

    Use repeat = code - base + 1 instead of a growing formula.

  4. Gateway to Program 12

    Next: same shrink, but letters advance A→E.

  5. Not a UI layout tool

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

Key benefit: one small program that proves inversion is usually a bound change — letter choice and width can flip independently.

🔮 Live Preview

Choose a row count between 1 and 26 and draw the inverted repeating alphabet triangle in the browser.

Try 5 (EEEEE…A), 4 (DDDD…A), or 7. Max 26 keeps letters in A–Z.

Live result
Press "Draw pattern".

Examples Gallery

Three complete Python programs — fixed top letter, CLI input, and a ch * repeat shortcut. Click View Output to reveal sample console results.

📚 Getting Started

Print five inverted rows with classic nested char loops.

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

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

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

How It Works

When i is ord('E'), the inner loop runs from A to E (5 times) and prints E. When i is ord('D'), it prints DDDD, and so on until a single A. Printing chr(i) (not the inner counter) keeps each row uniform.

📈 Practical Variant

Let the user choose the height at runtime.

Example 2 — User Input Version

Compute top = ord('A') + rows - 1, then shrink with repeat = code - base + 1. Wrap int(input()) in try/except ValueError in real apps.

Python
rows = int(input("Enter the number of rows: "))
rows = max(1, min(rows, 26))

base = ord('A')
top = base + rows - 1

for code in range(top, base - 1, -1):
    repeat = code - base + 1
    for _ in range(repeat):
        print(chr(code), end="")
    print()

How It Works

For rows = 4, top is ord('D'). Letter D repeats 4 times, C three times, and so on. Clamp rows to 1–26 so top stays within A–Z.

⚡ Shortcut Style

Same shape without an explicit inner print loop.

Example 3 — ch * repeat

Build each repeated-letter row in one call, then print it.

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

for code in range(top, base - 1, -1):
    repeat = code - base + 1
    print(chr(code) * repeat)

How It Works

chr(code) * repeat creates a string of length repeat filled with that letter. Great once you understand the nested-loop idea; keep the two-loop version for exams that ask you to show both bounds.

🧠 How the Algorithm Prints Rows

1

Set up

Use input() when reading input. Fix the top letter or compute it from rows.

Setup
2

Outer loop (letter)

for i in range(ord('E'), ord('A') - 1, -1): selects the character printed on the row.

E → A
3

Inner loop (width)

for j in range(ord('A'), i + 1): runs 5, 4, 3… times; print chr(i) with print(chr(i), end="").

5..1
4

New line

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

Break
=

Triangle complete

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

🔎 Worked Walkthrough — 'E' down to 'A'

Trace each outer-loop value of i and count how many times the inner loop runs.

iInner j rangePrinted rowRepeats
'E''A'..'E'EEEEE5
'D''A'..'D'DDDD4
'C''A'..'C'CCC3
'B''A'..'B'BB2
'A''A'..'A'A1

Total letter prints: 5 + 4 + 3 + 2 + 1 = 15 = 5×6/2.

Use Cases

Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.

1. Bound Flip Practice

Clearest demo that j <= i from A shrinks as i falls.

Example: compare with Program 10’s growing inner bound.

2. Pair with Program 10

Teach grow vs shrink as a one-bound change.

Example: side-by-side E/DD/CCC vs EEEEE/DDDD/CCC.

3. Char Math Labs

Practice code - base + 1 for shrinking widths.

Example: ord('D') - ord('A') + 1 = 4.

4. Case & Fill Variants

Swap to lowercase or mix digits once the loops work.

Example: start from chr(ord('a') + rows - 1).

5. Complexity Intuition

Descending triangular totals still make O(n²) concrete.

Example: 5+4+…+1 = 15 for n = 5.

6. Input Validation Labs

Pair the pattern with try/except ValueError and 1–26 clamps.

Example: reject rows <= 0 or rows > 26.

Pro Tip: say “outer picks the letter, inner shrinks the width” before coding — that story prevents mixing Program 10’s growing formula here.

Advantages

Why this pattern earns a spot right after the growing reverse triangle.

  1. 1. Instant Visual Feedback

    Wrong width formula shows up immediately as a growing instead of shrinking shape.

  2. 2. Minimal Concepts

    Only loops, chars, and console output — no arrays required.

  3. 3. Easy to Mirror

    Flip to Program 10 by growing the repeat count instead.

  4. 4. O(1) Extra Memory

    Streaming output needs no storage beyond loop counters.

Pro Tip: learn the nested-loop version first; treat ch * repeat as a polish shortcut afterward.

Usage Tips

Small habits that keep alphabet-pattern code clean.

  1. 1. Name the Roles

    Use ch for the row letter and repeat = code - base + 1 for the shrinking count.

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

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

  3. 3. Keep print() Outside

    Only call print() after the inner loop finishes the row.

  4. 4. Clamp to 26

    For A–Z demos, reject or clamp rows > 26.

  5. 5. Dry-Run One Small n

    Trace rows = 3 (CCC, BB, A) on paper before coding larger demos.

Pro Tip: if you get E, DD, CCC instead of EEEEE, DDDD, CCC, you reused Program 10’s growing repeat formula.

Common Pitfalls

Mistakes that commonly break inverted repeating alphabet patterns.

  1. 1. Printing j Instead of i

    Rows become A…E sequences instead of repeated letters.

    → Always print(chr(i), end="") (or ch) for this shape.

  2. 2. Using Program 10’s Growing Formula

    repeat = (ord(top) - ord(ch)) + 1 grows widths — wrong for this page.

    → Use repeat = code - base + 1 (or j from A to i).

  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 int(input()) in try/except ValueError and validate range.

  5. 5. rows > 26 Without a Policy

    chr(ord('A') + rows - 1) can leave the A–Z range.

    → Clamp to 26 or define wrap/error behavior explicitly.

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single letter

Output is just A on one line.

rows = 0

Empty pattern

Treat as invalid; re-prompt instead of silent empty output.

Negative

rows < 0

Invalid height — validate before computing top.

rows > 26

Past Z

Clamp or error — char math leaves A–Z.

Bad input

Non-numeric input

Non-numeric input becomes 0 — check try/except ValueError first.

Case

Lowercase variant

Same loops work with 'a' and chr(ord('a') + rows - 1).

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Flip to Program 10

  • Grow widths: E, DD, CCC, …
  • Continue with Program 10

2. Forward letters (Program 12)

  • Keep shrinking widths, advance A→E
  • See Program 12

3. Safe input loop

  • Use try/except ValueError until 1 <= rows <= 26
  • Then draw the triangle

4. Lowercase version

  • Use chr(ord('a') + rows - 1) as the top letter
  • Shows the loop structure is reusable

Notes

  • Triangular count. Total letters for n rows is still n(n+1)/2 — hence O(n²) time.
  • Print the outer letter; the inner loop only decides how many times (shrinking).
  • Validate 1 <= rows <= 26 for interactive A–Z programs.
  • This page is left-aligned. Centered pyramids need leading spaces — covered later in the series.

Quick Takeaway: outer loop picks the letter (counting down), inner loop shrinks the width, then break the line — that is the whole pattern.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–2)O(rows²)O(1)
ch * repeat (Example 3)O(rows²)O(rows) per row string (temporary)
Wrap Up

🎉 Conclusion

The inverted repeating alphabet triangle is a small nested-loop exercise with lasting payoff: outer letter vs shrinking width, char countdown, and O(n²) intuition. Master the classic two-loop version, then optionally shorten rows with ch * repeat.

Practice the three examples above, then compare with Program 10 or continue to Program 12’s forward-letter invert.

Print the outer letter with print(..., end=""), end rows with print(), and use code - base + 1 (not Program 10’s growing formula) for the width.

💡 Best Practices

✅ Do

  • Explain outer = letter, inner = shrinking width before coding
  • Use print(chr(i), end="") for letters and print() after each row
  • Validate 1 <= rows <= 26 for interactive programs
  • Check try/except ValueError after input()
  • State O(n²) time when asked about complexity

❌ Don’t

  • Print the inner-loop variable for this repeating shape
  • Reuse Program 10’s growing repeat formula here
  • Call print() inside the inner letter loop
  • Ignore bad console input in user-facing demos
  • Allow rows > 26 without a clear policy

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print the inverted repeating triangle the beginner-friendly way.

5
Core concepts
02

Outer loop

Picks the row letter

Code
A 03

Inner loop

Shrinks with print(chr(i), end="")

Code
04

print()

Ends each row

I/O
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

Program 10 prints widths 1..5 (E, DD, CCC, ...). Program 11 prints widths 5..1 (EEEEE, DDDD, ...). Both use repeating letters per row and letters counting down.
When i is ord('E'), the inner loop runs from A through E (5 times) and prints E each time. Next i becomes ord('D'), the inner loop runs 4 times and prints D.
The inner loop only controls how many times to print. Printing the outer letter keeps the entire row the same letter; printing the inner counter would step letters across the row.
Because the inner loop runs from ord('A') through i. Smaller i means fewer iterations, so fewer characters are printed.
print(ch, 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²) where n is the number of rows. Total printed characters equal n+(n-1)+…+1 = n(n+1)/2.
Yes. print(ch * repeat) prints a full repeated-letter row in one call. Nested loops are better for learning; ch * repeat is a handy shortcut later.
Use a try/except ValueError around int(input()), or check raw.isdigit() before converting, then clamp rows between 1 and 26 so bad input does not walk past Z.

Did you Know? 🔊

This is the inverted twin of Program 10: letters still step E→A, but widths shrink 5, 4, 3, …, 1 instead of growing. Print the outer loop letter inside the inner loop so each row stays uniform.

Continue to Alphabet Pattern 12

Keep the shrinking widths, but advance letters forward: AAAAA, BBBB, CCC, …

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