Python Repeating Alphabet Triangle Pattern

Beginner
7 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

A repeating alphabet triangle grows by one character each row, but every character on that row is the same letter — the letter advances with the row.

Remember
Rule: for row from 1 to n,
      print letter (A + row - 1) exactly row times

A
BB
CCC
DDDD
EEEEE     ← 5 rows

Unlike Program 1 (A, AB, ABC), letters do not step across the row — you print one letter row times. The reverse twin is Program 10 (E, DD, CCC, …).

How to Solve It

Two ways to emit the same shape — start with nested ord/chr loops, then optionally shorten with string multiplication.

MethodIdeaBest for
Nested loopsOuter = row/letter; inner = repeat count; print outer letterLearning, interviews, exams
ch * rowBuild a whole repeated-letter row in one expressionShorter demos once loops click

Pseudocode

Pseudocode
for row from 1 to rows:
    ch = letter at (A + row - 1)
    for count from 1 to row:
        print ch (no newline)
    print newline

Cheat sheet

GoalPattern
Walk each rowfor row in range(1, rows + 1):
Letter from rowch = chr(ord("A") + row - 1)
Grow widthfor _ in range(row):
Uniform rowprint(ch, end="") — print ch, not a stepping letter
End the rowprint()
One-line shortcutprint(ch * row)
Reverse twinProgram 10 (E, DD, CCC, …)

Printing Letters vs Starting a New Line

APIEffectUse for
print(ch, end="")Stays on the same lineEach letter on the row
print()Ends the current lineAfter the inner loop finishes a row

Print letters without a newline, then end the row once.

Live Preview

Change the row count and the repeating triangle updates instantly — including the triangular letter total.

Whole numbers from 1 to 10. Tap a chip or type a value — the preview redraws as you go.

Live result 5 rows · last E · 15 letters
A
BB
CCC
DDDD
EEEEE

Worked Walkthrough — rows = 4

Trace each row as row advances from 1 to 4.

rowLetterPrinted rowRepeats
1AA1
2BBB2
3CCCC3
4DDDDD4

Total letter prints: 1 + 2 + 3 + 4 = 10 = 4×5/2 — same triangular count as Program 1.

Python Programs

Three complete programs: fixed 5 rows, input() row-count, and a ch * row shortcut. Use View Output to reveal sample results.

Example 1 — Fixed A–E

Hard-coded height — outer loop picks the letter; inner loop only controls the repeat count.

Python
rows = 5

for row in range(1, rows + 1):
    ch = chr(ord("A") + row - 1)
    for _ in range(row):
        print(ch, end="")
    print()

How It Works

1. Outer loop picks the row. row runs from 1 to 5 — one letter per row.

2. Map row to a letter. ch = chr(ord("A") + row - 1) — for row = 3, ch is C.

3. Inner loop only counts. Print ch exactly row times with end="".

When row = 3 the inner loop runs three times and you get CCC.

Example 2 — Row Count Input

Read the height at runtime. Prefer try/except ValueError and a 1–26 clamp in real apps.

Python
rows = int(input("Enter the number of rows: "))
if rows < 1:
    raise SystemExit
if rows > 26:
    rows = 26

for row in range(1, rows + 1):
    ch = chr(ord("A") + row - 1)
    for _ in range(row):
        print(ch, end="")
    print()

How It Works

1. Prompt and read. Ask for a row count, then convert with int().

2. Same map and repeat. Letter and width still follow row — only the height comes from input.

3. Safer input tip. Prefer:

Safer input
try:
    rows = int(input("Enter the number of rows: "))
except ValueError:
    print("Enter a whole number from 1 to 26.")
    raise SystemExit

if rows < 1 or rows > 26:
    print("Enter a whole number from 1 to 26.")
    raise SystemExit

Example 3 — print(ch * row)

Build each repeated-letter row in one expression — same shape, no explicit inner letter loop.

Python
rows = 5

for row in range(1, rows + 1):
    ch = chr(ord("A") + row - 1)
    print(ch * row)

How It Works

1. One outer loop. Still walk row from 1 to rows and map it to a letter.

2. Build the row. ch * row creates a string of length row filled with ch.

3. Print and advance. Bare print(...) prints that string and ends the line.

Learn the two-loop version first (Examples 1–2) so you can explain both bounds; treat this as a polish shortcut afterward.

Edge Cases & Pitfalls

Check these before calling the solution done.

Wrong letter

Program 1 by mistake

If you print stepping letters across the row instead of a fixed ch, you get A, AB, ABC…. Always print the same letter row times.

print() early

Column of letters

If bare print() is inside the inner loop, each letter lands on its own line. Use end="" for letters; call print() only after the inner loop.

Wrong width

Rectangle, not triangle

Inner bound must grow with the row (range(row)). A fixed inner bound prints a filled rectangle.

rows = 1

Single A

Output is just A on one line — a good sanity check.

rows > 26

Beyond Z

Cap or reject — the row letter leaves the alphabet. Keep rows in 1…26 for A–Z demos.

Bad input

Use try/except

int(input()) raises on letters — prefer try/except ValueError and clamp to 1…26.

Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–2)O(n²)O(1)
ch * row (Example 3)O(n²)O(n) per temporary row string

Total letters printed = 1 + 2 + … + n = n(n+1)/2, which is still quadratic in n.

Key Takeaways

  • Rule: one letter per row; width grows 1, 2, 3, …
  • Print one letter: the inner loop only counts — print ch, not stepping letters.
  • Break the row: call print() only after the inner loop.
  • Complexity: O(n²) time; O(1) extra space for nested loops.

One line: for each row, print letter A + row - 1 exactly row times, then print().

Frequently Asked Questions

Because the inner loop prints the outer-loop letter (ch) every time. The inner counter only controls how many times to print, not which character to print.
Then letters would change across the row (A, AB, ABC…), which is Program 1 — not a repeating-letter triangle.
On the third row the letter is C (chr(ord('A') + 2)), and the inner loop runs three times, printing C each time.
Program 1 prints stepping letters across each row (A, AB, ABC). This pattern keeps one letter per row and only grows the repeat count (A, BB, CCC).
Program 10 uses the same growing widths but letters count downward (E, DD, CCC…). This pattern counts upward (A, BB, CCC…).
print(ch, end="") stays on the same line. Bare print() ends the current line. Letters use end=""; the row break uses print() after the inner loop.
O(n²) for n rows, because total printed characters are n(n+1)/2.
Yes. print(ch * row) prints a full repeated-letter row in one call. Nested loops are better for learning; ch * row is a handy shortcut later.

Did you know?

Each row prints the same letter repeatedly: row 1 prints A once, row 2 prints B twice, row 3 prints C three times. Letter = chr(ord('A') + row - 1). The reverse twin is Program 10.

Next: Reverse Repeating Triangle

Same growing widths, letters counting down — E, DD, CCC, BB, A.

Program 10 tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful