Mirrored Alphabet Pattern in Python

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
mirror halves

What You'll Learn

This pattern prints an increasing alphabet on the left and a decreasing alphabet on the right, with a shrinking space gap in the middle.

⭐ Pattern Output

When you run the program with rows = 5:

Output
A        A
AB      BA
ABC    CBA
ABCD  DCBA
ABCDEEDCBA
1

Complete Python Program

Fixed rows = 5 version (no magic ASCII numbers):

Python
rows = 5

base = ord('A')
top = base + rows - 1  # 'E'

for row in range(rows):  # 0..4
    left_end = base + row

    # Left half: A..(A+row) then spaces to fill width
    for code in range(base, top + 1):
        print(chr(code) if code <= left_end else " ", end="")

    # Right half: E..A then spaces to fill width (same condition)
    for code in range(top, base - 1, -1):
        print(chr(code) if code <= left_end else " ", end="")

    print()

🧠 How It Works

1

How far the alphabet reaches

For each row in 0..rows-1, left_end = base + row is the highest letter printed on that row (A, then B, then C, …).

Outer
2

Left sweep with padding

First loop walks every code from A to top. If code <= left_end, print the letter; else print a space. That leaves a widening gap toward the right half of the row.

Left
3

Right sweep mirrors the rule

Second loop goes from top down to A with the same condition, producing the descending mirror so spaces shrink until the halves meet on the last row.

Right
=

Closing mirror

Each row prints 2×rows slots in two passes — O(n²) time for n rows, O(1) extra space.

2

Variation — User Input Version

Read rows from input (clamped to 26):

Python
rows = int(input(\"Enter the number of rows (max 26): \"))\nrows = max(1, min(rows, 26))\n\nbase = ord('A')\ntop = base + rows - 1\n\nfor row in range(rows):\n    left_end = base + row\n\n    for code in range(base, top + 1):\n        print(chr(code) if code <= left_end else \" \", end=\"\")\n\n    for code in range(top, base - 1, -1):\n        print(chr(code) if code <= left_end else \" \", end=\"\")\n\n    print()

💡 Tips for Enhancement

Try These

  • Print lowercase letters by using ord('a') as the base
  • Replace spaces with dots to visualize the layout while debugging
  • Build each row as a string for easier testing

Avoid

  • Hardcoding ASCII numbers like 65 or 70
  • Changing the middle gap without adjusting both halves equally

Key Takeaways

1

Left side prints A up to a row-specific letter; the rest are spaces.

2

Right side prints E down to A using the same condition.

3

The middle gap shrinks by two each row and becomes zero on the last row.

❓ Frequently Asked Questions

On the final row, both halves are fully printed and the middle gap becomes zero spaces, so the left ABCDE touches the right EDCBA, producing ABCDEEDCBA.
For rows = n, the gap starts at 2*(n-1) spaces and decreases by 2 each row until it reaches 0.
It’s O(n²) for n rows, because each row prints O(n) characters across both halves.

Next: Python Alphabet Pattern 20

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

Program 20 →

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