Alphabet Pattern (A, ABC, ABCDE, ...) in Python

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
odd-length rows

What You'll Learn

This Python program prints an alphabet pattern where each row starts at A and prints an odd number of letters: 1, 3, 5, 7, and so on.

⭐ Pattern Output

When you run the program with rows = 5:

Output
A
ABC
ABCDE
ABCDEFG
ABCDEFGHI
1

Complete Python Program

Fixed rows = 5 version:

Python
rows = 5

base = ord('A')

for row in range(rows):  # 0..4
    letters = 2 * row + 1
    for code in range(base, base + letters):
        print(chr(code), end="")
    print()

🧠 How It Works

1

Odd-length rows

For row in 0..rows-1, letters = 2 * row + 1 yields widths 1, 3, 5, 7, 9, ….

Outer
2

Always start from A

The inner loop for code in range(base, base + letters) prints consecutive letters starting at A for every row, so each line is a fresh prefix of the alphabet.

Inner
3

End the row

Letters use end=""; print() after the inner loop adds the newline.

print
=

Odd pyramid

Total letters are 1+3+5+… = for n rows, so time is O(n²) and extra space is O(1).

2

Variation — User Input Version

Read rows from user input (clamped so we donโ€™t go beyond Z):

Python
rows = int(input("Enter rows (max 13): "))
rows = max(1, min(rows, 13))

base = ord('A')

for row in range(rows):
    letters = 2 * row + 1
    for code in range(base, base + letters):
        print(chr(code), end="")
    print()

💡 Tips for Enhancement

Try These

  • Switch to lowercase by using ord('a')
  • Add spaces between letters for readability
  • Center the rows to create a pyramid shape
  • Print only vowels or skip letters for a variation

Avoid

  • Hardcoding ASCII values like 66 or 76
  • Letting user input exceed the alphabet without handling it
  • Forgetting the newline after each row

Key Takeaways

1

Row r prints 2r + 1 letters.

2

Each row starts from A.

3

Prefer ord()/chr() over ASCII numbers.

❓ Frequently Asked Questions

This pattern prints odd counts per row: 1, 3, 5, 7, ... so each row increases by 2 letters.
Change rows. Row i (0-based) prints 2*i+1 letters, so the longest row prints 2*(rows-1)+1 letters.
It’s O(n²) for n rows, because the total printed characters grow roughly with n².

Next: Python Alphabet Pattern 15

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

Program 15 →

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