Shape Rule
Odd widths 1, 3, 5…
Each row prints the prefix A..end where end is A, C, E, G, I.

Each row is a block of letters from A through the next “odd step” in the alphabet: A, ABC, ABCDE, ABCDEFG, ABCDEFGHI. The outer loop steps the end letter by 2 (A, C, E, G, I) with range(..., 2). Compare Program 1 (step 1) and Program 13 (running counter). Includes a live preview, worked Python examples, edge cases, and complexity.
Odd widths 1, 3, 5…
Each row prints the prefix A..end where end is A, C, E, G, I.
Step by 2
for i in range(ord('A'), ord('I') + 1, 2): picks the end letter.
Print A..i
for j in range(ord('A'), i + 1): restarts at A every row.
Same line / next line
Letters use print(..., end=""); end each row with print().
1–13 rows
Pick a row count and draw the odd-length triangle in the browser.
Complexity
Total letters = r²; extra memory stays O(1).
An odd-length alphabet triangle grows by two letters on each new line. Every row still starts at A, but the ending letter jumps A → C → E → G → I, so widths are 1, 3, 5, 7, 9.
In Python you usually solve it with two nested for loops: the outer loop steps the end letter by 2, the inner loop prints A through that end letter, then print() moves to the next line.
It shows that changing only the outer step (1 vs 2) transforms Program 1 into an odd-width triangle — and that odd-number sums equal perfect squares, which makes complexity analysis concrete.
Row lengths are 1, 3, 5, 7, 9, …
Outer end letter jumps with range(..., 2).
Inner loop always restarts at A.
Odd sum identity: total prints equal r².
In short: for each end letter i stepping A, C, E, …, print A..i with print(chr(j), end=""), then call print().
Given a row count r (or a fixed odd-step ending letter like 'I'), print a left-aligned triangle of alphabet prefixes with odd lengths.
# First 5 rows (conceptual shape)
# A
# ABC
# ABCDE
# ABCDEFG
# ABCDEFGHI | Item | Type | Description |
|---|---|---|
rows / end letter | int / char | Number of odd-length lines (1–13 for A–Y), or last end letter such as 'I'. |
| Printed output | text | Left-aligned rows; row k prints letters from A through 'A' + 2*(k-1). |
for i from ord('A') to end step 2:
for j from ord('A') to i:
print chr(j) (no newline)
print newline | Approach | Idea | Best for |
|---|---|---|
range(..., 2) / end = base + 2*(row-1) | Outer end letter steps by two | Learning and interviews |
| Row index formula | end = ord('A') + 2*(row-1) | Clearer when input is a row count |
| Goal | Pattern |
|---|---|
| Step end letters | for i in range(ord('A'), ord('I') + 1, 2): |
| Print prefix A..i | for (j = 'A'; j <= i; j++) print(chr(j), end="") |
| End the row | print() |
| End from row index | end = ord('A') + 2 * (row - 1) |
| Step-1 triangle | See Program 1 (A, AB, ABC, …) |
Same triangle — different roles for each tool.
same linePrints a letter without moving to the next line
new lineEnds the current row after the prefix is printed
odd endsJumps the ending letter A → C → E …
step +2In Python, use range(..., 2) / end = base + 2*(row-1)
Reach for this triangle when practicing loop steps and odd-width prefixes.
Change only the outer step from 1 to 2 for odd widths.
Practice += 2 on chars and int row formulas.
Odd sums equal squares — count printed letters for small r.
Next: symmetric alphabet rows with a star center.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one small program that links loop step size, odd widths, and the classic odd-sum = square identity.
Choose a row count between 1 and 13 and draw the odd-length alphabet triangle in the browser.
Three complete Python programs — fixed through I, ending-letter input, and a row-count formula. Click View Output to reveal sample console results.
Print five odd-length rows with a step-2 end letter.
'I'Hard-coded ending letter — ideal for first demos and screenshots.
for i in range(ord('A'), ord('I') + 1, 2):
for j in range(ord('A'), i + 1):
print(chr(j), end="")
print() When i is ord('A'), the inner loop prints A. When i is ord('C'), it prints ABC, and so on through ABCDEFGHI. In Python, step end letters with range(ord('A'), end + 1, 2) so the step is built into the loop.
Let the user choose the last ending letter.
Read an odd-step ending letter (A, C, E, …). Prefer validating a single A–Z character in real apps.
raw = input("Enter the ending letter (odd step like I): ").strip().upper()
end = ord(raw[0]) if raw else ord('I')
for i in range(ord('A'), end + 1, 2):
for j in range(ord('A'), i + 1):
print(chr(j), end="")
print() Same nested-loop core as Example 1; only the outer upper bound changes. Prefer odd-step endings (A, C, E, …) so every row length stays odd from the start.
Drive the pattern from a row count instead of an ending letter.
end = ord('A') + 2*(row-1)Clear when the user enters how many rows to print.
rows = 5
base = ord('A')
for row in range(1, rows + 1):
end = base + 2 * (row - 1)
for j in range(base, end + 1):
print(chr(j), end="")
print() Row 1 ends at ord('A') + 0, row 2 at ord('A') + 2, row 3 at ord('A') + 4, and so on. Clamp rows to 1–13 so end stays within A–Y.
Use input() when reading input. Choose a last end letter or a row count.
i takes A, C, E, G, I via range(ord('A'), ..., 2).
j always starts at A and prints every letter up to the current i.
print() ends the row so the next outer iteration starts fresh.
Total letters: 1+3+…+(2r-1) = r² — O(r²) time, O(1) extra memory.
'I'Trace each outer-loop value of i and count how many letters the inner loop prints.
i | Inner j range | Printed row | Length |
|---|---|---|---|
'A' | 'A'..'A' | A | 1 |
'C' | 'A'..'C' | ABC | 3 |
'E' | 'A'..'E' | ABCDE | 5 |
'G' | 'A'..'G' | ABCDEFG | 7 |
'I' | 'A'..'I' | ABCDEFGHI | 9 |
Total letter prints: 1 + 3 + 5 + 7 + 9 = 25 = 5².
Where this tiny pattern (and its step-by-2 idea) shows up beyond the homework prompt.
Clearest demo that the outer increment controls width growth.
Example: change += 2 to += 1 and watch Program 1 appear.
Teach step size as a one-line difference between patterns.
Example: side-by-side A/AB/ABC vs A/ABC/ABCDE.
Count letters to see that odd totals equal squares.
Example: 5 rows → 25 = 5² prints.
Lowercase or spaced letters once the loops work.
Example: start from 'a' with the same += 2.
Square totals make O(r²) concrete without triangular formulas.
Example: r = 10 → 100 letter prints.
Practice both ending-letter and row-count APIs for the same shape.
Example: map rows=3 ↔ end='E'.
Pro Tip: say “outer picks the odd end letter, inner prints A through that end” before coding — that story prevents forgetting to restart at A.
Why this pattern earns a spot right after the classic A/AB/ABC triangle.
Wrong step size shows up immediately as consecutive widths instead of odd ones.
Only nested loops and a step of 2 — no arrays required.
Flip back to Program 1 by changing the outer step to 1.
Total work is exactly r² — memorable for interviews.
Pro Tip: learn the step-2 end-letter version first; treat the row-index formula as an equivalent rewrite afterward.
Small habits that keep odd-length alphabet code clean.
Use range(..., 2) or end = base + 2*(row-1) — do not use step 1 by accident.
Use A, C, E, …, Y when you want clean odd lengths from row 1.
Inner loop must begin at 'A' every row for this prefix shape.
Row 13 ends at Y; row 14 would leave A–Z.
Trace 3 rows (A / ABC / ABCDE) on paper before coding larger demos.
Pro Tip: if you get A, AB, ABC instead of A, ABC, ABCDE, you used step 1 instead of step 2.
Mistakes that commonly break odd-length alphabet patterns.
You get Program 1’s consecutive widths (A, AB, ABC, …).
→ Keep range(..., 2) or end = base + 2*(row-1).
iSkipping A produces single letters or wrong prefixes.
→ Always restart the inner loop at ord('A').
Using range(..., 1) (or no step) recreates Program 1’s A, AB, ABC shape.
→ Keep range(..., 2) or end = base + 2*(row-1).
Empty tokens or non-letters produce unexpected ending letters.
→ Validate a single A–Z letter, or take a row count with try/except ValueError.
Beyond 13 rows the end letter leaves A–Z.
→ Clamp to 1–13 or stop when end > 'Z'.
Check these inputs before calling the solution done.
Output is just A on one line.
Prints A / ABC / ABCDE.
Still runs, but odd-length alignment from A is messier — prefer odd-step ends.
End letter Y; 13² = 169 prints.
Validate before taking the first character of the input string.
Same loops work with 'a' and += 2.
Try these variations to lock in the pattern.
r²r² — hence O(r²) time.A.range(..., 2) or the row-index end formula.Quick Takeaway: outer loop steps the end letter by 2, inner loop prints A through that end, then break the line — that is the whole pattern.
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–3) | O(r²) | O(1) |
Because 1+3+…+(2r-1)=r², the letter count is exactly a perfect square.
The odd-length alphabet triangle is a small nested-loop exercise with lasting payoff: outer step size, prefix printing, and the odd-sum = square identity. Master the step-2 end-letter version, then optionally drive it from a row count with end = ord('A') + 2*(row-1).
Practice the three examples above, then continue to Program 15’s symmetric alphabet-with-stars pattern.
Step the end letter by 2, always restart the inner loop at A, and remember total prints equal r².
range(..., 2) or the row-index end formula'A' every rowr² when asked about complexityPrint the odd-length triangle the beginner-friendly way.
Odd widths via step 2
DefinitionEnd letters A, C, E…
CodePrints A..end each row
CodeEnds each row
I/OO(r²) time
AnalysisOdd numbers add up to perfect squares: 1+3+5+…+(2r-1)=r². That is why this pattern prints exactly r² letters for r rows — the same count that makes the complexity O(r²).
Next up: symmetric alphabet rows with stars filling the center.
12 people found this page helpful