Reverse Alphabet Pattern (EDCBA to A) in Python

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
n(n+1)/2 letters total

What You'll Learn

This Python program prints a reverse alphabet pattern where each row starts from a decreasing letter and ends at A.

For n rows, the total letters printed are 1 + 2 + … + n = n(n + 1)/2.

⭐ Pattern Output

When you run the program with rows = 5:

Output
EDCBA
DCBA
CBA
BA
A
1

Complete Python Program

Fixed rows = 5 version:

Python
rows = 5

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

for i in range(rows):  # 0..4
    start = top - i
    for code in range(start, base - 1, -1):
        print(chr(code), end="")
    print()

🧠 How It Works

1

Letter range with ord()

base = ord('A') and top = base + rows - 1 map the first row start to the top letter (e.g. E when rows = 5).

Setup
2

Outer loop: row start moves down

for i in range(rows) runs once per row. start = top - i so the first character printed shifts E → D → C … each line.

Outer
3

Inner loop: print down to A

for code in range(start, base - 1, -1) walks codes from the row start down to A; chr(code) turns each into a letter.

Reverse
=

Shrinking reverse rows

Row lengths are n, n−1, …, 1. Total letters are n(n+1)/2, so time is O(n²) and extra space is O(1).

2

Variation — User Input Version

Read rows from user input (clamped to 26):

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

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

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

💡 Tips for Enhancement

Try These

  • Print lowercase output using ord('a')
  • Add spaces between letters for readability
  • Start from a fixed top letter like Z
  • Mirror the output to build a diamond-like shape

Avoid

  • Hardcoding ASCII values like 69
  • Letting rows exceed 26 without handling wrap-around
  • Forgetting the newline after each row

Key Takeaways

1

Row i starts at top - i and counts down to A.

2

Use range(..., ..., -1) for descending sequences.

3

Total printed letters are \(n(n+1)/2\), so runtime is O(n²).

❓ Frequently Asked Questions

For rows = 5, the top letter is computed as 'A' + (rows - 1), which is E. The first row prints from that top letter down to A.
Compute top = ord('A') + rows - 1. For row i (0-based), print from top - i down to ord('A').
It’s O(n²) for n rows, because the program prints 1+2+…+n letters in total.

Next: Python Alphabet Pattern 8

Continue to Program 8 for another reverse alphabet pattern.

Program 8 →

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