Reverse Alphabet Pattern (E to EDCBA) 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 fixed letter (E for rows = 5) and grows by one descending letter.

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
E
ED
EDC
EDCB
EDCBA
1

Complete Python Program

Fixed rows = 5 version (computed top letter):

Python
rows = 5

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

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

🧠 How It Works

1

Pick the top letter

top = ord('A') + rows - 1 selects the starting letter for every row. For rows = 5, the top becomes ord('E').

Setup
2

Outer loop: one row per i

for i in range(1, rows + 1) runs once per row. Row i prints exactly i letters.

Outer
3

Inner loop: descending codes

range(top, top - i, -1) generates top, top-1, ..., top-i+1. Each chr(code) prints a letter, and print(..., end="") keeps the row on one line.

Inner
=

Descending alphabet rows

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))

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()

💡 Tips for Enhancement

Try These

  • Start from a fixed letter (e.g., always 'Z') instead of tying it to rows
  • Print lowercase by using ord('a') as the base
  • Add spaces between letters for readability
  • Try reversing each row to get DE, CDE, ...

Avoid

  • Hardcoding ASCII values like 69 when ord() is clearer
  • Allowing rows > 26 without defining wrap-around behavior
  • Forgetting to print a newline after each row
  • Building huge strings in a loop when printing directly is enough

Key Takeaways

1

Compute the top letter from rows using ord('A') + rows - 1.

2

Row i prints i letters in descending order.

3

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

4

range(..., ..., -1) is the key for reverse sequences.

5

Clamp user input to 26 rows to stay within A to Z.

❓ Frequently Asked Questions

Yes. Set top = ord('Z') and keep the same inner loop. You may also clamp rows so you donโ€™t go before A.
Because it starts at top, steps by -1, and stops before top - i. That yields exactly i values: top down to top - i + 1.
It’s O(n²) for n rows, because the program prints 1+2+…+n letters in total.

Next: Python Alphabet Pattern 3

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

Program 3 →
Did you know?

In Python, you can iterate backwards easily with range(start, stop, -1) — perfect 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