Reverse Alphabet Repeat Pattern (E, DD, CCC, BBBB, AAAAA) in Python

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

What You'll Learn

This Python program prints a pattern where each row repeats one letter, and the letter moves backward from E to A while the repeat count increases from 1 to 5.

Total printed characters for rows = n is \(1 + 2 + \cdots + n = \frac{n(n+1)}{2}\).

⭐ Pattern Output

When you run the program with rows = 5:

Output
E
DD
CCC
BBBB
AAAAA
1

Complete Python Program

Nested loop version:

Python
rows = 5

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

for row in range(1, rows + 1):
    letter_code = top - (row - 1)
    for _ in range(row):
        print(chr(letter_code), end="")
    print()

🧠 How It Works

1

Top letter and row index

top = base + rows - 1 is the first row’s letter. For each row from 1 to rows, letter_code = top - (row - 1) moves the letter backward (E, D, C, …).

Setup
2

Repeat count grows with the row

The inner loop runs row times, so line lengths are 1, 2, 3, … while the printed letter steps down the alphabet.

Inner
3

Finish each row

Same-line printing uses end=""; print() after the inner loop ends the row.

print
=

Reverse letter, longer rows

Total characters are n(n+1)/2, so time is O(n²) and extra space is O(1).

2

Variation — String Repetition Version

More idiomatic Python using string repetition:

Python
rows = 5

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

for row in range(1, rows + 1):
    ch = chr(top - (row - 1))
    print(ch * row)

💡 Tips for Enhancement

Try These

  • Print lowercase by using ord('a') as the base
  • Clamp rows to 26 to stay within A–Z
  • Add a space between repeated characters (e.g., (ch + ' ') * row)
  • Reverse the direction to print A, BB, CCC, ...

Avoid

  • Hardcoding ASCII values like 70
  • Forgetting the newline after each row
  • Letting rows exceed 26 without defining behavior
  • Overcomplicating: string repetition is usually the cleanest approach

Key Takeaways

1

Row i prints the same letter i times.

2

The letter decreases from E to A when rows = 5.

3

Total output size is \(n(n+1)/2\), so time is O(n²).

4

Prefer ord()/chr() over ASCII numbers.

5

String repetition (ch * row) is concise and readable.

❓ Frequently Asked Questions

Yes. Use string repetition: compute the row letter and print ch * row.
Use chr(base + (row - 1)) instead of subtracting from top.
It’s O(n²) for n rows, because the program prints 1+2+…+n characters in total.

Next: Python Alphabet Pattern 11

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

Program 11 →
Did you know?

In Python, repeating strings like "A" * 5 is a common and efficient way to build pattern rows.

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