Alphabet Pattern (A, BB, CCC, DDDD, ...) in Python

What You'll Learn
This program prints an increasing repetition pattern: row 1 prints A, row 2 prints BB, row 3 prints CCC, and so on.
The letter advances by one each row, while the repetition count equals the row number.
⭐ Pattern Output
When you run the program with rows = 5:
A
BB
CCC
DDDD
EEEEEComplete Python Program (Nested Loops)
This version uses a nested loop to print each character one by one.
rows = 5
rows = max(1, min(rows, 26))
base = ord('A')
for row in range(1, rows + 1):
ch = chr(base + (row - 1))
for _ in range(row):
print(ch, end="")
print()🧠 How It Works
One row per row
for row in range(1, rows + 1) visits rows 1 through rows. The letter for that row is chr(base + (row - 1)) (A, then B, then C, …).
Repeat the letter row times
The inner for _ in range(row) prints the same character row times on one line, giving A, BB, CCC, …
New line after each row
print(ch, end="") keeps letters on the same row; the bare print() after the inner loop starts the next row.
Growing repeats
You print 1+2+…+n = n(n+1)/2 characters, so runtime is O(n²) and memory beyond the output is O(1).
Variation — String Repetition (Concise)
Same output using Python's string * count repetition.
rows = 5
rows = max(1, min(rows, 26))
base = ord('A')
for row in range(1, rows + 1):
ch = chr(base + (row - 1))
print(ch * row)💡 Tips for Enhancement
Try These
- Print lowercase letters using
base = ord('a') - Print spaced output like
A,B B,C C C - Start from a custom letter (e.g.,
start = 'D')
Avoid
- Hardcoding ASCII values like
65or70 - Allowing
rowsabove 26 without wrap-around logic
Key Takeaways
Each row prints a single character repeated row times.
Use chr(base + offset) to move from A to B to C...
Total printed letters are \(n(n+1)/2\), so runtime is O(n²).
❓ Frequently Asked Questions
base = ord('a') instead of ord('A').print(ch * count).Next: Python Alphabet Pattern 10
Continue to Program 10 for the reverse repeated-letter pattern.
10 people found this page helpful
