Alphabet Pattern (ABCDE 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 an alphabet pattern where every row ends at a fixed letter (E for rows = 5) and the start letter moves forward 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
ABCDE
BCDE
CDE
DE
E
1

Complete Python Program

Fixed rows = 5 version:

Python
rows = 5

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

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

🧠 How It Works

1

Compute the end letter

end = ord('A') + rows - 1 sets a fixed row ending letter. With rows = 5, that end becomes E.

Setup
2

Move start forward each row

For row i, we set start = base + i. This produces starts A, B, C, D, E.

Start
3

Print from start to end

range(start, end + 1) prints letters from the row start through the fixed end letter. The final print() moves to the next line.

Inner
=

Shorter rows that still end at E

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')
end = base + rows - 1

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

💡 Tips for Enhancement

Try These

  • Print lowercase letters by using ord('a') as the base
  • Add spaces between letters for readability
  • Fix the end letter to Z and clamp rows to avoid going beyond the alphabet
  • Reverse each row to get EDCBA, EDCB, ...

Avoid

  • Hardcoding ASCII values like 65 or 70
  • 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 end letter based on rows.

2

Move the start letter forward one step per row.

3

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

4

Use ord()/chr() for clean character arithmetic.

5

Clamp user input to 26 to stay within AZ.

❓ Frequently Asked Questions

Python ranges are end-exclusive, so using range(start, end + 1) includes the end 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 7

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

Program 7 →
Did you know?

Patterns that shift their start index each row are a great way to practice translating math bounds into loop ranges.

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