Decreasing Alphabet Pattern (ABCDE to A) 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 decreasing alphabet pattern. The first row prints rows letters from A, and each next row prints one less.

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
ABCDE
ABCD
ABC
AB
A
1

Complete Python Program

Fixed rows = 5 version:

Python
rows = 5

base = ord('A')

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

🧠 How It Works

1

Set a base letter

base = ord('A') stores the numeric code for A. We’ll print letters by converting back using chr().

Setup
2

Outer loop: decreasing row length

for i in range(rows, 0, -1) produces rows, rows-1, ..., 1. So each next row is shorter by one letter.

Outer
3

Inner loop: print A to A+i-1

range(base, base + i) iterates through the first i letter codes starting from A. Using end="" keeps the row on one line.

Inner
=

Decreasing rows

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

💡 Tips for Enhancement

Try These

  • Print lowercase output by using ord('a')
  • Add spaces between letters for readability
  • Start from a different letter and limit the max rows accordingly
  • Try printing the decreasing pattern in reverse (A, AB, ABC, ...)

Avoid

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

Key Takeaways

1

Use a decreasing outer loop to shorten each row.

2

The inner loop prints from A up to the row end letter.

3

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

4

Use ord()/chr() for clean character arithmetic.

5

Clamp input to 26 to stay within AZ.

❓ Frequently Asked Questions

Yes. Use print(chr(code), end=" ") inside the inner loop, then print a newline after the row.
Because there are 26 English letters. Clamping keeps the output within A to Z without wrapping.
It’s O(n²) for n rows, because the program prints 1+2+…+n letters in total.

Next: Python Alphabet Pattern 6

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

Program 6 →
Did you know?

Decreasing patterns like this are a great way to practice loop bounds and end-exclusive ranges 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