Step 01 Beginner Problems — Patterns
Pattern 16 — Alpha-Ramp Pattern
A ramp of letters where each row is one letter repeated: 'A', then 'B B', then 'C C C'. The letter climbs the alphabet as you go down while the repetition count climbs with it — both the value and the count are read off the row index.
A B B C C C D D D D E E E E E
How to think about it
Number the rows i = 0, 1, ..., n-1. Row i consists of the single letter chr(ord('A') + i) repeated i + 1 times. Nothing depends on the column at all: within a row every token is identical, so the inner loop degenerates to a repetition. This is Pattern 4 (the repeated-number triangle) translated into letters — value from the row index, count = row index + 1.
Code
The code computes the row's letter once, ch = chr(ord('A') + i), builds a list of i + 1 copies with [ch] * (i + 1), and prints it joined. Because the token is constant within the row, list multiplication replaces the inner loop entirely, just as in Pattern 4.
def pattern(n):
for i in range(n):
ch = chr(ord("A") + i)
print(" ".join([ch] * (i + 1)))Key points
- Row i: letter = chr(ord('A') + i), count = i + 1 — both from the row index alone.
- Constant rows are built with [token] * count; no inner loop needed.
- This is Pattern 4 with letters — same formulas, character tokens.
- Row 0 must be a single 'A'; if you see 'B' first, your offset is wrong.
- The right edge forms a staircase while the letters form a ramp — hence the name.