Alphabet Pattern (E, DE, CDE, BCDE, ABCDE) 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 an alphabet pattern where each row ends at a fixed top letter (E for rows = 5) while the starting letter moves backward 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
E
DE
CDE
BCDE
ABCDE
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):
    start = top - (i - 1)
    for code in range(start, top + 1):
        print(chr(code), end="")
    print()

🧠 How It Works

1

Pick the top letter

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

Setup
2

Compute the row start

For row i, we start at start = top - (i - 1). That gives starts E, D, C, B, A for rows 1 through 5.

Start
3

Print ascending to the top

range(start, top + 1) prints letters from the row’s start up to the fixed top letter. Using end="" keeps letters on the same line.

Inner
=

Expanding from the left

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):
    start = top - (i - 1)
    for code in range(start, top + 1):
        print(chr(code), end="")
    print()

💡 Tips for Enhancement

Try These

  • Change the base letter to print lowercase patterns
  • Add spaces between letters for readability
  • Reverse each row to get ED, EDC, ...
  • Try centering the output for a pyramid effect

Avoid

  • Hardcoding ASCII values like 70 or 69
  • Allowing rows > 26 without defining wrap-around behavior
  • Forgetting a newline after each row
  • Mixing tabs/spaces in Python snippets

Key Takeaways

1

Fix a top letter (top) and compute per-row start.

2

Row i prints from start through top.

3

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

4

Use ord() and chr() for clean letter arithmetic.

5

Clamp user input to 26 to stay within AZ.

❓ Frequently Asked Questions

Yes. Set top = ord('Z') and clamp rows so the computed start does not go before A.
Python ranges are end-exclusive, so range(start, top + 1) includes the top letter.
It’s O(n²) for n rows, because the program prints 1+2+…+n letters in total.

Next: Python Alphabet Pattern 4

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

Program 4 →
Did you know?

In Python, you can build each row as a string too (e.g., with ''.join(...)), but printing inside nested loops is perfect for learning.

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