Alphabet-Star Mirror Pattern (ABCDEEDCBA) in Python

Beginner
⏱️ 8 min read
📚 Updated: Aug 2025
🎯 2 Code Examples

What You'll Learn

This Python program prints an alphabet mirror on both sides and fills the middle with stars. As rows progress, letters shrink and the star block grows.

⭐ Pattern Output

When you run the program with rows = 5:

Output
ABCDEEDCBA
ABCD**DCBA
ABC****CBA
AB******BA
A********A
1

Complete Python Program

Nested loops version:

Python
rows = 5

base = ord('A')

for i in range(rows, 0, -1):
    # Left: A..(A+i-1)
    for code in range(base, base + i):
        print(chr(code), end="")

    # Middle: 2*(rows-i) stars
    stars = 2 * (rows - i)
    for _ in range(stars):
        print("*", end="")

    # Right: (A+i-1)..A
    for code in range(base + i - 1, base - 1, -1):
        print(chr(code), end="")

    print()

🧠 How It Works

1

Shrink the letter span each row

for i in range(rows, 0, -1) uses i as how many letters appear on each side. Row 5 prints A–E forward and E–A backward; later rows use fewer letters.

Outer
2

Left then stars then right

First loop: base to base + i - 1. Middle: 2 * (rows - i) stars. Last loop: codes from base + i - 1 down to A.

Three parts
3

Mirror symmetry

The right loop is the reverse of the left prefix, so the row reads the same forward and backward except for the growing star block in the center.

Mirror
=

Stars fill the gap

Each row still does O(rows) prints; over n rows that is O(n²) time and O(1) extra space.

2

Variation — User Input Version

Read rows from user input (clamped to 26):

Python
rows = int(input("Enter the number of rows (max 26): "))
rows = max(1, min(rows, 26))

base = ord('A')

for i in range(rows, 0, -1):
    for code in range(base, base + i):
        print(chr(code), end="")

    stars = 2 * (rows - i)
    print("*" * stars, end="")

    for code in range(base + i - 1, base - 1, -1):
        print(chr(code), end="")

    print()

💡 Tips for Enhancement

Try These

  • Use lowercase by switching ord('A') to ord('a')
  • Change the filler character from * to - or #
  • Add spaces between letters for readability
  • Build each row as a string (useful for unit tests)

Avoid

  • Hardcoding ASCII values like 65
  • Letting rows exceed 26 without defining behavior
  • Forgetting the newline after each row

Key Takeaways

1

Left side prints ascending letters; right side prints descending letters.

2

Stars in the middle are 2*(rows-i).

3

Use ord()/chr() instead of ASCII numbers.

❓ Frequently Asked Questions

The left side prints A..E and the right side prints E..A, so the top letter appears twice in the middle.
For total rows n and current i (counting down), the middle has 2*(n-i) stars.
It’s O(n²) for n rows, because total printed characters grow proportionally to n².

Next: Python Alphabet Pattern 16

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

Program 16 →

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