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

What You'll Learn
This Python program prints a pattern where each row repeats the same letter, while the letter increases from A to E and the repeat count decreases from 5 to 1.
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:
AAAAA
BBBB
CCC
DD
EComplete Python Program
Nested loop version:
rows = 5
base = ord('A')
for i in range(rows): # 0..4
ch = chr(base + i)
repeat = rows - i
for _ in range(repeat):
print(ch, end="")
print()🧠 How It Works
Row index and letter
for i in range(rows) walks 0…rows-1. Each row’s letter is ch = chr(base + i) (A, B, C, …).
Repeat count shrinks
repeat = rows - i is the number of copies on that row: full width on the first row, then one fewer each time.
Print and newline
The inner loop prints ch repeat times with end="", then print() ends the row.
Wider top, advancing letter
Total output length is n(n+1)/2 — O(n²) time, O(1) extra space.
Variation — String Repetition Version
More idiomatic Python using string repetition:
rows = 5
base = ord('A')
for i in range(rows):
ch = chr(base + i)
repeat = rows - i
print(ch * repeat)💡 Tips for Enhancement
Try These
- Print lowercase by using
ord('a')as the base - Clamp rows to 26 to stay within A–Z
- Add spaces between letters for readability
- Reverse the pattern to print
EEEEE,DDDD, ...
Avoid
- Hardcoding ASCII values like
65or70 - 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 multiple times.
The repeat count decreases from 5 to 1 (for rows = 5).
Total output size is \(n(n+1)/2\), so time is O(n²).
Prefer ord()/chr() over ASCII numbers.
String repetition (ch * repeat) is concise and readable.
❓ Frequently Asked Questions
print(ch * repeat).base = ord('A') to your starting letter and clamp rows so you donโt exceed Z.n rows, because the program prints 1+2+…+n characters in total.Next: Python Alphabet Pattern 13
Continue to Program 13 for the next alphabet pattern in Python.
Using string repetition like "B" * 4 is one of the simplest ways to generate pattern rows in Python.
10 people found this page helpful
