Reverse Alphabet Pyramid (E to A) in Python

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
reverse, right-aligned

What You'll Learn

This program prints a reverse alphabet pyramid using nested loops. With rows = 5 it starts at E and expands: E, E D, E D C, E D C B, E D C B A.

⭐ Pattern Output

When you run the program with rows = 5:

Output
        E
      E D
    E D C
  E D C B
E D C B A
1

Complete Python Program

Fixed rows = 5 version (same idea as the classic ASCII approach, but using ord()/chr()):

Python
rows = 5

base = ord('A')
top = base + rows - 1  # 'E' when rows = 5

for i in range(top, base - 1, -1):  # E..A (controls row)
    code = top + 1                  # reset per row (like k = 70)
    for j in range(base, top + 1):  # A..E (controls column)
        if j >= i:
            code -= 1
            print(chr(code), end=" ")
        else:
            print(" ", end=" ")
    print()

🧠 How It Works

1

Top and base letters

base = ord('A') and top = base + rows - 1 set the letter range for the pyramid (A through E for 5 rows).

Setup
2

Outer loop controls how many letters appear

for i in range(top, base - 1, -1) moves the threshold from E down to A. As i decreases, more columns satisfy j >= i, so each row prints one more letter.

Outer
3

Reset and print descending letters

Each row resets code = top + 1. For every column where j >= i, the program decrements code and prints chr(code), producing E D C ... on that row.

Inner
=

Right-aligned reverse pyramid

Row lengths are 1..n, so total letters are n(n+1)/2. The nested loops scan n columns per row, so time is O(n²) with O(1) extra space.

2

Variation — User Input Version

Read rows from input. Clamped to 1–6 so n(n+1)/2 letters stay within A–Z (6 rows → 21 letters):

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

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

for i in range(top, base - 1, -1):
    code = top + 1
    for j in range(base, top + 1):
        if j >= i:
            code -= 1
            print(chr(code), end=" ")
        else:
            print(" ", end=" ")
    print()

💡 Tips for Enhancement

Try These

  • Use lowercase by setting base = ord('a')
  • Replace the inner printing with building a list, then join it for cleaner spacing
  • If you need more than 6 rows, wrap letters with modulo arithmetic

Avoid

  • Hardcoding ASCII like 70 or 69 instead of using ord()
  • Forgetting to reset the per-row counter — otherwise rows won’t start at the top letter

Key Takeaways

1

Use top = ord('A') + rows - 1 to compute the starting letter.

2

Reset code per row so each row begins at the same top letter.

3

Total letters are n(n+1)/2, so keep rows small unless you wrap.

❓ Frequently Asked Questions

Because the code resets code to top + 1 at the start of every row and then prints descending letters where j >= i, making the first printed letter always E.
Yes. Change end=\" \" to end=\"\" for letters, and adjust padding so the alignment still looks centered.
It’s O(n²) for n rows because each row scans all columns.

Next: Python Alphabet Pattern 24

Continue to Program 24 for the next alphabet pattern in Python.

Program 24 →

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.

10 people found this page helpful