A reverse-start alphabet triangle keeps the right edge fixed at a top letter while each new row begins one letter earlier — letters along the row still run forward.
Remember
Rule: start moves E→A; print start..top forward
E
DE
CDE
BCDE
ABCDE ← 5 rows, every row ends at E
Compare Program 1 (always starts at A) and Program 2 (letters descend along the row). Program 4 reverses order inside each row instead.
Approach
How to Solve It
Outer loop picks the first letter (top down to A). Inner loop prints forward from that letter up to top.
Method
Idea
Best for
Code points (ord/chr)
range(code, top + 1) prints start..top
Classic nested-loop drills
Spaced cells
print(chr(j) + " ", end="")
Easier-to-scan columns
Pseudocode
Pseudocode
top = 'E' // or 'A' + rows - 1
for code from top down to 'A': // start letter
for j from code to top: // forward run
print j
print newline
Cheat sheet
Goal
Pattern
Fixed top
top = ord("E")
Rows → top
top = ord("A") + rows - 1
Walk starts
for code in range(top, ord("A") - 1, -1):
Print forward
for j in range(code, top + 1): print(chr(j), end="")
End the row
print()
vs Program 1
Here the start moves; Program 1 grows the end
vs Program 2
Here letters increase; Program 2 decreases along the row
Printing Letters vs Starting a New Line
API
Effect
Use for
print(chr(j), end="")
Stays on the same row
Each letter in the forward run
print()
Ends the current row
After the inner loop
Print letters without a newline, then end the row once.
Try it
Live Preview
Change the row count and the reverse-start triangle updates instantly — including the fixed top letter on every row.
Whole numbers from 1 to 10. Size 5 means top letter E. Tap a chip or type a value — the preview redraws as you go.
Live result5 rows · top E
E
DE
CDE
BCDE
ABCDE
Trace
Worked Walkthrough — rows = 3 (top = C)
Outer start moves C → B → A. Inner loop always ends at C.
Start code
Inner run
Printed row
C
C..C
C
B
B..C
BC
A
A..C
ABC
Total letters are 1+2+…+n = n(n+1)/2 → O(n²).
Code
Python Programs
Three complete programs: fixed top E, row-count input(), and spaced letters. Use View Output for sample results.
Example 1 — Fixed Top E
Outer loop chooses the first letter; inner loop prints forward up to E.
Python
top = ord("E")
for code in range(top, ord("A") - 1, -1):
for j in range(code, top + 1):
print(chr(j), end="")
print()
Output
E
DE
CDE
BCDE
ABCDE
How It Works
1. Fix the right edge.top = ord("E") so every row ends at E.
2. Move the start. Outer code walks E → D → … → A.
3. Print forward. When start is C, the inner loop prints C, D, E → CDE.
Example 2 — Row Count Input
Read how many rows to print and compute top = ord("A") + rows - 1. Cap at 26 so the top letter stays in A–Z.
Python
raw = input("Enter the number of rows: ").strip()
try:
rows = int(raw)
except ValueError:
print("Please enter a whole number.")
raise SystemExit(1)
rows = max(1, min(rows, 26))
top = ord("A") + rows - 1
for code in range(top, ord("A") - 1, -1):
for j in range(code, top + 1):
print(chr(j), end="")
print()
Output (when user enters 4)
D
CD
BCD
ABCD
How It Works
1. Validate rows. Parse an integer, then clamp to 1..26.
2. Derive top. For 4 rows, top becomes D, so every row ends at D.
Example 3 — Spaced Letters
Print a space after each letter so columns are easier to scan.
Python
top = ord("E")
for code in range(top, ord("A") - 1, -1):
for j in range(code, top + 1):
print(chr(j) + " ", end="")
print()
Output
E
D E
C D E
B C D E
A B C D E
How It Works
1. Same loops. Start still moves E→A; letters still run forward to E.
2. Extra space.chr(j) + " " separates letters without changing the pattern logic.
Edge Cases & Pitfalls
Check these before calling the solution done.
wrong direction
Inner loop goes backward
Printing top..code gives Program 2’s descending rows (E, ED, EDC). Keep range(code, top + 1).
off-by-one
range(top, ord("A"), -1)
Stopping before A skips the full last row. Use ord("A") - 1 as the exclusive end.
newline early
Bare print() inside the inner loop
Use end="" for letters; call bare print() only after the forward run.
rows > 26
Top past Z
Cap rows at 26 so ord("A") + rows - 1 stays in A–Z.
rows = 1
Single A
Output is just A — a good sanity check.
Bad input
Non-integer rows
Catch ValueError from int(...) before computing top.
Analysis
Time and Space Complexity
Program
Time
Extra space
Fixed / input (Examples 1–2)
O(n²)
O(1)
Spaced letters (Example 3)
O(n²)
O(1)
There are n rows and row r prints r letters, so total work is n(n+1)/2.
Remember
Key Takeaways
Rule: start moves backward; letters along the row still increase to a fixed top.
Right edge: every row ends at the same top letter (E for 5 rows).
Contrast: Program 1 grows the end; Program 2 descends along the row.
Next step: Program 4 reverses letter order inside each row.
One line: for each start from top down to A, print start..top forward, then newline.
Frequently Asked Questions
The outer loop moves the starting letter from E down to A. The inner loop always prints forward from that start letter up to E (or top), so the last character remains E on every row.
Program 2 prints letters descending along the row (E, ED, EDC). This program prints forward along the row (E, DE, CDE) while only the row's first letter moves backward.
Program 1 always starts at A and grows the end letter (A, AB, ABC). This pattern grows the start letter backward while keeping the right edge fixed at top.
Yes. Read rows with input(), set top = ord('A') + rows - 1, then loop code from top down to ord('A') and print j from code up to top.
O(n²) for n rows, because the total printed letters are 1+2+...+n = n(n+1)/2.
Use try/except ValueError around int(input()), require n ≥ 1, and cap at 26 so the top letter stays within A–Z.
Because the inner loop always stops at top (E in the fixed example), so the last printed character is always that same letter.
Yes. Use ord('a') as the base: top = ord('a') + rows - 1, then loop the same way with range(code, top + 1).
🤔
Did you know?
This triangle changes only the starting letter of each row (E, D, C, …), while letters along the row still increase forward. In the 5-row example, every row ends at E, producing E, DE, CDE, BCDE, ABCDE.