Python Sequential Alphabet Triangle Pattern

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

What Is This Pattern?

A sequential alphabet triangle grows like a right-angled star triangle, but letters keep advancing across the whole figure — they do not reset to A on each row.

Remember
Rule: one running char k; print then k++
      Row i prints i letters

A
B C
D E F
G H I J
K L M N O     ← 5 rows (15 letters, A–O)

Contrast with Program 1, where every row starts over at A. Here a single k lives outside the outer loop and only moves forward.

How to Solve It

Keep one letter cursor, print it on each cell, then advance — optionally separate letters with spaces.

MethodIdeaBest for
Spaced rowsprint(chr(k), end=""), optional space, then k += 1Readable demos, interviews
Compact rowsSame k += 1 logic without spacesDenser output once the idea clicks

Pseudocode

Pseudocode
k = 'A'
for i from 1 to rows:
    for j from 1 to i:
        print k (no newline)
        if j < i: print " " (no newline)
        k = next letter
    print newline

Cheat sheet

GoalPattern
Start the cursork = ord('A') before the outer loop
Walk each rowfor i in range(1, rows + 1):
Print i lettersfor j in range(1, i + 1):
Advance foreverprint(chr(k), end=""); k += 1
Space between lettersif j < i: print(" ", end="")
End the rowprint()
A–Z-safe heightrows*(rows+1)//2 ≤ 26 → max 6 rows

Printing Letters vs Starting a New Line

APIEffectUse for
print(..., end="")Stays on the same lineEach letter and each space
print()Ends the current lineAfter the inner loop

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

Live Preview

Change the row count and the sequential triangle updates instantly — including letter totals and the last letter used.

Whole numbers from 1 to 7. Six rows stay in A–Z (21 letters); seven needs 28 and continues past Z.

Live result 5 rows · A–O · 15 letters
A
B C
D E F
G H I J
K L M N O

Worked Walkthrough — rows = 4

Trace each outer value of i and watch k keep advancing — never reset.

iLetters printedPrinted rowk after row
1AAB
2B, CB CD
3D, E, FD E FG
4G…JG H I JK

Total letters: 1 + 2 + 3 + 4 = 10 = 4×5/2. That triangular sum is why time is O(n²).

Python Programs

Three complete programs: fixed height with spaces, input(), and a compact no-space variant. Use View Output to reveal sample results.

Example 1 — Fixed rows = 5

Hard-coded height with spaces between letters — ideal for first demos.

Python
k = ord('A')

for i in range(1, 6):
    for j in range(1, i + 1):
        print(chr(k), end="")
        if j < i:
            print(" ", end="")
        k += 1
    print()

How It Works

1. Start the cursor. k = ord('A') before any loop — it must outlive each row.

2. Outer loop picks the row width. Row i prints exactly i letters.

3. Inner loop prints and advances. Print chr(k), optional space, then k += 1 so the next cell gets the next letter.

4. Break the line. Bare print() after the inner loop; k keeps its value for the next row.

Example 2 — User Input Version

Read the height at runtime. Prefer try/except ValueError and clamp for A–Z.

Python
raw = input("Enter the number of rows: ").strip()

try:
    rows = int(raw)
except ValueError:
    print("Please enter a whole number of rows >= 1.")
else:
    if rows < 1:
        print("Please enter a whole number of rows >= 1.")
    else:
        if rows * (rows + 1) // 2 > 26:
            rows = 6

        k = ord('A')
        for i in range(1, rows + 1):
            for j in range(1, i + 1):
                print(chr(k), end="")
                if j < i:
                    print(" ", end="")
                k += 1
            print()

How It Works

1. Prompt and parse. Ask for a row count, then convert with int(...) inside try/except ValueError.

2. Same running-k core. Only the outer bound changes — the print and advance logic matches Example 1.

3. A–Z clamp. Cap at 6 rows when rows*(rows+1)//2 > 26 so letters stay in A–Z for demos.

Example 3 — No Spaces

Same sequence without spaces between letters — denser formatting only.

Python
k = ord('A')

for i in range(1, 6):
    for j in range(1, i + 1):
        print(chr(k), end="")
        k += 1
    print()

How It Works

1. Same cursor. k still starts at ord('A') and advances after every letter.

2. Drop the spacer. Remove the if j < i: print(" ", end="") line — the sequence is unchanged.

3. Same row break. Bare print() still ends each row after the inner loop.

Edge Cases & Pitfalls

Check these before calling the solution done.

Reset k each row

Program 1 by mistake

If you set k = ord('A') inside the outer loop, every row restarts at A. Keep k outside.

k += 1 once per row

Repeated letters

Increment inside the inner loop after each print. Advancing only once per row repeats the same letter across wide rows.

print early

Column of letters

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

Past Z

Cap the height

Seven rows need 28 letters. Cap so n(n+1)/2 ≤ 26, or stop when k > ord('Z').

rows = 1

Single A

Output is just A — a good sanity check.

Bad input

Catch ValueError

Bare int(input()) raises on letters — wrap in try/except ValueError.

Time and Space Complexity

ProgramTimeExtra space
Spaced / compact loopsO(rows²)O(1)

Total letters printed = 1 + 2 + … + n = n(n+1)/2, which is still quadratic in n. Spaces add only a linear factor of the same order.

Key Takeaways

  • One cursor: declare k before the outer loop and never reset it per row.
  • Print then advance: print(chr(k), end=""); k += 1 on every inner-loop step.
  • Break the row: end="" for letters/spaces; bare print() after the inner loop.
  • Complexity: O(n²) time from the triangular letter count; O(1) extra space.

One line: for each row i, print the next i letters from a shared cursor k, then print().

Frequently Asked Questions

Because k is updated after every printed character and is not reset inside the outer loop. That is what makes the sequence continuous across the triangle.
A single running character starts at A and increments after every print. Row 1 prints 1 character, row 2 prints 2, row 3 prints 3, so you see consecutive letters across the whole triangle.
Because each cell must print a new next letter. If you incremented only once per row, the wider rows would repeat the same letter.
print(ch, end="") stays on the same line. print() ends the current line. Letters (and optional spaces) use end=""; the row break uses print() after the inner loop.
1+2+…+n = n(n+1)/2. For 5 rows that is 15 letters (A through O).
O(n²) where n is the number of rows. Total printed letters equal n(n+1)/2.
Plain code += 1 continues past Z into the next Unicode/ASCII values. Cap rows so n(n+1)/2 ≤ 26, or stop when the code exceeds ord('Z'), if you want A–Z only.
Use a try/except ValueError around int(input()), then clamp rows so the triangular letter count stays in range for your alphabet policy (max 6 for A–Z).

Did you know?

Unlike Program 1 (letters reset to A each row), this pattern uses one running character that increments after every print. Letters stay consecutive across the whole triangle: A, then B C, then D E F, and so on.

Next: Odd-Length Triangle

Rows grow as A, ABC, ABCDE, … — end letter steps by two each time.

Program 14 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