Continuous Alphabet Triangle Pattern in Python

What You'll Learn
This program prints a triangle where letters continue from row to row (they donโt restart at A each time).
⭐ Pattern Output
When you run the program with rows = 5:
A
B C
D E F
G H I J
K L M N OComplete Python Program
Fixed rows = 5 version (no magic ASCII numbers):
rows = 5
base = ord('A')
code = base
for row in range(1, rows + 1):
letters = []
for _ in range(row):
letters.append(chr(code))
code += 1
print(" ".join(letters))🧠 How It Works
Running letter counter
code = ord('A') tracks the next letter globally. It never resets between rows, so the alphabet continues across the whole triangle.
Build one row as a list
For each row, the inner loop runs row times, appending chr(code) and then doing code += 1.
Join with spaces
print(" ".join(letters)) prints the row with spaces between letters on a single line.
Continuous triangle
Row r adds r letters, so total letters are n(n+1)/2 — O(n²) time; the list per row is O(row) auxiliary space.
Variation — User Input Version
Read rows from user input (clamped to 6 so we stay within A–Z):
rows = int(input("Enter the number of rows (max 6): "))
rows = max(1, min(rows, 6))
code = ord('A')
for row in range(1, rows + 1):
letters = []
for _ in range(row):
letters.append(chr(code))
code += 1
print(" ".join(letters))💡 Tips for Enhancement
Try These
- Print lowercase letters by starting from
ord('a') - Change spacing (use
"-".join(letters)or tabs) - Increase max rows by switching to a larger alphabet set (wrap-around or Unicode)
Avoid
- Hardcoding ASCII values like
64or69 - Letting rows exceed the alphabet size without defining behavior
- Printing extra trailing spaces at the end of each row
Key Takeaways
Keep a running code value so letters continue across rows.
Each row prints row letters separated by spaces.
Total printed letters are \(n(n+1)/2\), so runtime is O(n²).
❓ Frequently Asked Questions
rows = 7 would need 28 letters (past Z), but rows = 6 needs only 21.n rows, because the program prints 1+2+…+n letters in total.Next: Python Alphabet Pattern 14
Continue to Program 14 for the odd-length alphabet row pattern.
10 people found this page helpful
