Step 01 Beginner Problems — Patterns
Pattern 14 — Increasing Letter Triangle Pattern
The growing triangle dressed in letters: row one is 'A', row two is 'A B', and each row restarts at A and runs one letter further than the row above. It maps the number logic of Pattern 3 onto characters using character codes.
A A B A B C A B C D A B C D E
How to think about it
Number the rows i = 0, 1, ..., n-1. Row i has i + 1 letters: A, B, C, ..., up to the (i+1)-th letter. The letter at column j is chr(ord('A') + j) — you add the column offset to A's character code and convert back. The row always restarts from A (the value depends on the column, not on any running state), and the last letter of row i is chr(ord('A') + i). For n up to 26 the letters stay inside A-Z; beyond that the classic pattern is not defined.
Code
A list comprehension generates chr(ord('A') + j) for j in range(i + 1) — the letters from A up to the row's last letter — and the row is printed joined by spaces. All the machinery of Pattern 3 carries over; only the token generator changed, from str(j + 1) to a character computation.
def pattern(n):
for i in range(n):
letters = [chr(ord("A") + j) for j in range(i + 1)]
print(" ".join(letters))Key points
- Letter at column j: chr(ord('A') + j) — character arithmetic replaces number formatting.
- Row i ends at the (i+1)-th letter and always restarts at A.
- Same skeleton as Pattern 3: the outer loop sets the length, the inner generates from the column.
- Defined for n <= 26; beyond Z the alphabet runs out.
- In C++ or Java the same trick is char('A' + j) — the idea is portable across languages.