Alphabet Repeat Pattern (AAAAA, BBBB, CCC, DD, E) 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 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:

Output
AAAAA
BBBB
CCC
DD
E
1

Complete Python Program

Nested loop version:

Python
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

1

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, …).

Outer
2

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.

Width
3

Print and newline

The inner loop prints ch repeat times with end="", then print() ends the row.

Inner
=

Wider top, advancing letter

Total output length is n(n+1)/2O(n²) time, O(1) extra space.

2

Variation — String Repetition Version

More idiomatic Python using string repetition:

Python
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 65 or 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 multiple times.

2

The repeat count decreases from 5 to 1 (for 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 * repeat) is concise and readable.

❓ Frequently Asked Questions

Yes. Print each row using string repetition: print(ch * repeat).
Change base = ord('A') to your starting letter and clamp rows so you donโ€™t exceed Z.
It’s O(n²) for 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.

Program 13 →
Did you know?

Using string repetition like "B" * 4 is one of the simplest ways to generate pattern rows in Python.

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