Reverse Alphabet Triangle (A to EDCBA) in Python

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
n(n+1)/2 letters total

What You'll Learn

This Python program prints a triangle pattern where each row starts from the current letter and counts down to A.

For n rows, the total letters printed are 1 + 2 + … + n = n(n + 1)/2.

⭐ Pattern Output

When you run the program with rows = 5:

Output
A
BA
CBA
DCBA
EDCBA
1

Complete Python Program

Fixed rows = 5 version:

Python
rows = 5

base = ord('A')

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

🧠 How It Works

1

Choose the base letter

base = ord('A') stores the numeric code for A. Using ord() avoids magic numbers like 65.

Setup
2

Outer loop: row index

for i in range(rows) runs from 0 to rows - 1. Row i prints i + 1 letters.

Outer
3

Inner loop: count down to A

range(base + i, base - 1, -1) counts down from the row’s starting letter to A (inclusive). Each chr(code) converts a number back to a letter.

Inner
=

Reverse rows ending at A

Total prints are 1+2+…+n = n(n + 1)/2, so runtime is O(n²) and extra space is O(1).

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):
    for code in range(base + i, base - 1, -1):
        print(chr(code), end="")
    print()

💡 Tips for Enhancement

Try These

  • Print lowercase by changing ord('A') to ord('a')
  • Add spaces between letters (e.g., end=" ")
  • Start from a different base letter (like 'C')
  • Try mirroring the triangle to create a diamond

Avoid

  • Hardcoding ASCII values like 65
  • Allowing rows > 26 without defining behavior
  • Forgetting to print a newline after each row
  • Mixing tabs/spaces in Python code examples

Key Takeaways

1

Row i starts at A + i and counts down to A.

2

Use range(start, stop, -1) for descending sequences.

3

Total printed letters are \(n(n+1)/2\), so runtime is O(n²).

4

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

5

Clamp user input to 26 rows to stay within the alphabet.

❓ Frequently Asked Questions

Yes. Use print(chr(code), end=" ") inside the inner loop, then print a newline after the row.
Change base = ord('A') to your preferred starting letter, and adjust the row limit so it doesn’t go past Z.
It’s O(n²) for n rows, because the program prints 1+2+…+n letters in total.

Next: Python Alphabet Pattern 5

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

Program 5 →
Did you know?

Reverse ranges in Python (negative step) are also used for countdown timers and reverse array indexing — not just patterns.

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