Reverse Alphabet Pattern (EDCBA to E) 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 at a fixed top letter (E for rows = 5) and ends one letter earlier each row.

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
EDCB
EDC
ED
E
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):
    stop = base + i
    for code in range(top, stop - 1, -1):
        print(chr(code), end="")
    print()

🧠 How It Works

1

Compute the top letter

top = ord('A') + rows - 1 sets the fixed starting letter for every row. With rows = 5, it becomes E.

Setup
2

Move the stop letter forward

For row i, we set stop = base + i. That gives stop letters A, B, C, D, E as rows progress.

Stop
3

Print from top down to stop

range(top, stop - 1, -1) prints the descending letters for each row. The final print() starts the next row on a new line.

Inner
=

Shrinking rows from the end

Total prints are 1+2+…+n = n(n + 1)/2, so runtime 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):
    stop = base + i
    for code in range(top, stop - 1, -1):
        print(chr(code), end="")
    print()

💡 Tips for Enhancement

Try These

  • Print lowercase output by using ord('a') as the base
  • Add spaces between letters for readability
  • Fix the top letter to Z and clamp rows to keep the stop within the alphabet
  • Mirror the output to build a diamond pattern

Avoid

  • Hardcoding ASCII values like 69 or 65
  • Letting rows exceed 26 without defining behavior
  • Forgetting the newline after each row
  • Mixing tabs/spaces in Python examples

Key Takeaways

1

Compute a fixed top letter using ord('A') + rows - 1.

2

Move the stop letter forward each row to shrink the line.

3

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

4

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

5

Clamp user input to 26 to stay within AZ.

❓ Frequently Asked Questions

Because Python ranges are end-exclusive. range(top, stop - 1, -1) includes the stop letter.
Yes. Print with end=" " in the inner loop, then print a newline after each row.
It’s O(n²) for n rows, because the program prints 1+2+…+n letters in total.

Next: Python Alphabet Pattern 9

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

Program 9 →
Did you know?

Python’s range() can count backwards with a negative step, which is handy for reverse alphabet and reverse number patterns.

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