Continuous Alphabet Triangle (Decreasing Rows) in Python

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
continuous letters

What You'll Learn

This program prints a decreasing triangle where letters continue across rows: first 5 letters, then 4, then 3, then 2, then 1.

⭐ Pattern Output

When you run the program with rows = 5:

Output
A B C D E\nF G H I\nJ K L\nM N\nO
1

Complete Python Program

Fixed rows = 5 version (cleaned from the reference logic; no ASCII constants like 64):

Python
rows = 5

code = ord('A')

for row_len in range(rows, 0, -1):  # 5, 4, 3, 2, 1
    for _ in range(row_len):
        print(chr(code), end=" ")
        code += 1
    print()

🧠 How It Works

1

One running letter counter

code = ord('A') stores the next letter to print. It is never reset, so letters continue from row to row.

State
2

Outer loop chooses row length

for row_len in range(rows, 0, -1) produces 5, 4, 3, 2, 1 for rows = 5. That’s why each next row is shorter.

Outer
3

Inner loop prints and increments

The inner loop runs row_len times. Each time it prints chr(code) and then does code += 1 to move to the next letter.

Inner
=

Continuous decreasing triangle

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

2

Variation — User Input Version

Read rows from input. Clamped to 1–6 so total letters n(n+1)/2 stay within A–Z (6 rows → 21 letters):

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

code = ord('A')

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

💡 Tips for Enhancement

Try These

  • Use lowercase by starting from ord('a')
  • Start from another letter (like ord('F')) to shift the sequence
  • Wrap after Z using modulo arithmetic if you want more rows

Avoid

  • Hardcoding ASCII values like 64 or 70
  • Letting rows exceed 6 without handling wrap-around

Key Takeaways

1

The outer loop sets row sizes as rows..1.

2

One counter prints a continuous alphabet across all rows.

3

Total letters are n(n+1)/2 — keep n small to stay within A–Z.

❓ Frequently Asked Questions

Move code = ord('A') inside the outer loop so it resets before printing each row.
Yes. Build a list of letters for the row and use \" \".join(row_letters).
It’s O(n²) because total printed characters are proportional to n(n+1)/2.

Next: Python Alphabet Pattern 26

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

Program 26 →

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