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

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:
E
DD
CCC
BBBB
AAAAAComplete Python Program
Nested loop version:
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
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, …).
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.
Finish each row
Same-line printing uses end=""; print() after the inner loop ends the row.
Reverse letter, longer rows
Total characters are n(n+1)/2, so time is O(n²) and extra space is O(1).
Variation — String Repetition Version
More idiomatic Python using string repetition:
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
Row i prints the same letter i times.
The letter decreases from E to A when rows = 5.
Total output size is \(n(n+1)/2\), so time is O(n²).
Prefer ord()/chr() over ASCII numbers.
String repetition (ch * row) is concise and readable.
❓ Frequently Asked Questions
ch * row.chr(base + (row - 1)) instead of subtracting from top.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.
In Python, repeating strings like "A" * 5 is a common and efficient way to build pattern rows.
10 people found this page helpful
