Continuous Alphabet Triangle (Decreasing Rows) in Python

Beginner
⏱️ 8 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Nested Loops

What You’ll Learn

Each row is shorter than the last, but letters stay in order across the whole shape: A B C D E, then F G H I, then J K L, M N, and O for five rows. This combines a shrinking outer loop with the running counter from Program 13 — unlike Program 5, letters never reset. Includes a live preview, worked Python examples, edge cases, and complexity.

Shape Rule

Shrink width, keep sequence

Row 1 prints rows letters; each next row prints one fewer — down to 1.

Running Char

Never reset

code = ord('A') lives outside the outer loop and advances across rows.

Decreasing Outer Loop

range(rows, 0, -1)

for row_len in range(rows, 0, -1): picks how many letters this row prints.

print end= vs print()

Same line / next line

Letters use print(..., end=" "); end each row with print().

Live Preview

1–6 rows

Pick a row count and draw the continuous decreasing triangle in the browser.

O(n²)

Complexity

Total letters = n(n+1)/2; extra memory stays O(1).

Introduction

A continuous alphabet triangle with decreasing rows starts with the longest line and shortens by one letter each row — but the alphabet never restarts. Letters flow continuously: the last letter on one row is followed by the next letter on the next row.

In Python you solve it with nested for loops, a decreasing outer bound range(rows, 0, -1), and a running code counter that increments after every print.

Why it matters?

It merges two ideas from earlier patterns: shrinking row width (Program 5) and a continuous counter (Program 13). Once both click, you can mix width rules with any ordered token stream.

Key Highlights

Continuous Letters

One code walks A, B, C… across the whole triangle.

Width Shrinks

Outer loop prints rows, rows−1, …, 1 letters per row.

Increment Per Cell

code += 1 belongs inside the inner loop, not after the row.

Not Program 5

Program 5 resets to A each row; this one never resets.

In short: start code = ord('A'), loop row_len from rows down to 1, print row_len letters with print(chr(code), end=" ") then code += 1, and call print() after each row.

📝 Problem & Approach

Given a positive integer rows, print a left-aligned triangle of consecutive alphabet letters where the first row has rows letters, each next row one fewer, and the sequence never resets.

Python
# First 5 rows (with spaces)
# A B C D E
# F G H I
# J K L
# M N
# O

Inputs & Outputs

ItemTypeDescription
rowsintNumber of triangle lines. For A–Z only, keep rows(rows+1)/2 ≤ 26 (max 6 full rows = 21 letters).
Printed outputtextLeft-aligned consecutive letters; spaces between letters on a row.

Minimal workflow

Pseudocode
code = ord('A')
for row_len from rows down to 1:
    for each letter in this row:
        print chr(code) with trailing space
        code += 1
    print newline

Approach comparison

ApproachIdeaBest for
Running codeDecreasing outer width + inner print/code += 1Learning and interviews
" ".join(row)Build a list per row, join with spacesClean output without trailing space
Reset-per-row styleSee Program 5 (ABCDE, ABCD, …)When each row starts from A

⚡ Quick Reference

GoalPattern
Start the sequencecode = ord('A') (outside outer loop)
Shrink row widthfor row_len in range(rows, 0, -1):
Print next letterprint(chr(code), end=" "); code += 1
Clean row (no trailing space)print(" ".join(row))
End the rowprint()
Growing continuous rowsSee Program 13 (A, B C, D E F, …)

📋 Program 13 vs Program 5 vs This Pattern

Same tools — different width rule and reset policy.

Program 13
grow rows
continuous

Width 1, 2, 3…; running counter — A, B C, D E F

Program 5
shrink rows
reset A

Width n, n−1…; each row starts from A — ABCDE, ABCD

Program 25 (this)
shrink rows
continuous

Width n, n−1…; running counter — A B C D E, F G H I

Learning tip
no reset

Do not set code = ord('A') inside the outer loop

Context

When This Pattern Shows Up

Reach for a shrinking outer loop plus running counter when width and sequence rules differ.

  1. After Program 13 and 5

    Combine growing/shrinking width with reset vs continuous fill.

  2. Reverse outer bounds

    Practice range(rows, 0, -1) with immediate visual feedback.

  3. Digit / token fills

    Same idea works with numbers or any ordered token stream.

  4. Gateway to Program 26

    Next: alphabet rotation rows (ABCDE, BCDEA, …).

  5. Not a UI layout tool

    This is a console teaching pattern — not how you build modern app screens.

Key benefit: one program that proves you can mix any width rule with a continuous counter — a skill used far beyond alphabet demos.

🔮 Live Preview

Choose a row count between 1 and 6 and draw the continuous decreasing alphabet triangle in the browser (spaces between letters).

Try 5 (through O) or 3 (A B C / D E / F). Six rows use 21 letters (A–U).

Live result
Press "Draw pattern".

Examples Gallery

Three complete Python programs — fixed five rows, console input, and a join-based variant without trailing spaces. Click View Output to reveal sample console results.

📚 Getting Started

Print five decreasing rows with a running character and spaces.

Example 1 — Fixed rows = 5

Hard-coded height — ideal for first demos and screenshots.

Python
rows = 5
code = ord('A')

for row_len in range(rows, 0, -1):
    for _ in range(row_len):
        print(chr(code), end=" ")
        code += 1
    print()

How It Works

code starts at ord('A') and never resets. The outer loop walks row_len from 5 down to 1; the inner loop prints that many consecutive letters. code += 1 after each letter keeps the sequence continuous.

📈 Practical Variant

Let the user choose the height at runtime.

Example 2 — User Input Version

Read rows and clamp to 1–6 for A–Z demos. Wrap int(input()) in try/except ValueError in real apps.

Python
try:
    rows = int(input("Enter number of rows (max 6): "))
except ValueError:
    print("Please enter a whole number.")
    raise SystemExit(1)

rows = max(1, min(rows, 6))
code = ord('A')

for row_len in range(rows, 0, -1):
    for _ in range(row_len):
        print(chr(code), end=" ")
        code += 1
    print()

How It Works

Same running-code core as Example 1; only the outer bound and clamp change. Six rows need 21 letters (A–U) — still inside A–Z.

⚡ Clean Output Style

Build each row as a list and join — no trailing space.

Example 3 — " ".join(row) Variant

Collect letters in a list, then join with spaces for tidy rows.

Python
rows = 5
code = ord('A')

for row_len in range(rows, 0, -1):
    row = []
    for _ in range(row_len):
        row.append(chr(code))
        code += 1
    print(" ".join(row))

How It Works

The code += 1 logic is identical; only formatting changes. " ".join(row) inserts spaces between letters without a trailing space at the end of the line.

🧠 How the Algorithm Prints Rows

1

Set up

Start code = ord('A') before the outer loop. Optionally read and clamp rows.

Setup
2

Outer loop (width)

for row_len in range(rows, 0, -1): decides how many letters this row prints — longest first.

n..1
3

Inner loop (cells)

Print chr(code), optional space, then code += 1 so the next cell gets the next letter.

code += 1
4

New line

print() ends the row; code keeps its value for the next (shorter) row.

Break
=

Triangle complete

Total letters: 1+2+…+n = n(n+1)/2O(n²) time, O(1) extra memory.

🔎 Worked Walkthrough — rows = 5

Trace each outer-loop value of row_len and watch how code advances across the whole triangle.

row_lencode before rowPrinted rowcode after row
5'A'A B C D E'F'
4'F'F G H I'J'
3'J'J K L'M'
2'M'M N'O'
1'O'O'P'

Total letter prints: 5 + 4 + 3 + 2 + 1 = 15 = 5×6/2 (A through O).

Use Cases

Where this tiny pattern (and its running counter plus shrinking width) shows up beyond the homework prompt.

1. Combine Two Ideas

Merge Program 13’s counter with Program 5’s decreasing width.

Example: side-by-side ABCDE/ABCD vs A B C D E/F G H I.

2. Reverse Range Practice

Reinforce range(rows, 0, -1) with a continuous fill check.

Example: trace row_len 5, 4, 3 on paper before coding.

3. Number Triangles

Swap code for an integer counter to print 1 2 3 4 5 / 6 7 8 9 / …

Example: start n = 1 and print/increment the same way.

4. Formatting Variants

Use join, commas, or no spaces without changing the sequence logic.

Example: Example 3 uses " ".join(row) for clean rows.

5. Complexity Intuition

Triangular totals make O(n²) concrete for beginners.

Example: 5 rows → 15 letters (A–O).

6. Alphabet Bounds Labs

Pair the pattern with a “stop at Z” or clamp policy.

Example: cap rows at 6 so 21 letters stay in A–Z.

Pro Tip: say “outer loop shrinks width; one counter walks the alphabet” before coding — that story prevents resetting code each row.

Advantages

Why this pattern earns a spot after the growing and reset-per-row triangles.

  1. 1. Two Skills in One

    Practices both reverse outer bounds and continuous state in a single program.

  2. 2. Minimal Concepts

    Only loops, one extra char, and console output.

  3. 3. Easy to Adapt

    Swap letters for digits, flip to growing rows, or use join formatting with tiny edits.

  4. 4. O(1) Extra Memory

    Streaming output needs no storage beyond loop counters and code.

Pro Tip: keep code outside the outer loop; resetting it each row accidentally recreates Program 5’s shape with a different letter rule.

Usage Tips

Small habits that keep continuous decreasing-pattern code clean.

  1. 1. Name the Runner

    Use code or nextLetter for the sequence — keep row_len for width.

  2. 2. Wrap int(input()) in try/except

    Avoid crashes when the user types letters instead of a number.

  3. 3. Increment Per Cell

    Put code += 1 inside the inner loop, after printing.

  4. 4. Clamp for A–Z Demos

    Six rows use 21 letters; cap at 6 when you want A–Z only.

  5. 5. Dry-Run One Small n

    Trace rows = 3 (A B C / D E / F) on paper before coding larger demos.

Pro Tip: if every row starts with A, you almost certainly reset code inside the outer loop — that is Program 5, not this pattern.

Common Pitfalls

Mistakes that commonly break continuous decreasing alphabet patterns.

  1. 1. Resetting code Each Row

    Setting code = ord('A') inside the outer loop recreates Program 5’s reset-style triangle.

    → Declare and initialize code once, before the outer loop.

  2. 2. Using Growing Outer Loop

    range(1, rows + 1) prints Program 13’s growing continuous triangle, not this one.

    → Use range(rows, 0, -1) for decreasing row lengths.

  3. 3. print() Inside the Inner Loop

    Each letter lands on its own line — you get a column, not a triangle.

    → Use print(..., end=" ") for letters; print() only after the inner loop.

  4. 4. Blind int(input())

    Non-numeric input raises ValueError with bare int(input()).

    → Wrap int(input()) in try/except ValueError and validate range.

  5. 5. Ignoring the Z Boundary

    Large rows walk past 'Z' into non-letter characters.

    → Cap rows at 6 for A–Z demos or stop when code > ord('Z').

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single letter

Output is just A on one line.

rows = 0

Empty pattern

Treat as invalid; re-prompt instead of silent empty output.

rows = 6

Max A–Z demo

21 letters (A–U). Last row is a single letter U.

rows > 6

Past Z

More than 21 letters needed — clamp or define wrap/stop policy.

Bad input

Non-numeric input

Use try/except ValueError before clamping rows.

Case

Lowercase variant

Same loops work with code = ord('a').

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Compare with Program 13

  • Growing width vs shrinking width
  • Both use continuous code
  • See Program 13

2. Compare with Program 5

  • Both shrink row width
  • Reset A vs continuous counter
  • See Program 5

3. Number version

  • Print 1 2 3 4 5 / 6 7 8 9 / …
  • Same loops, int counter

4. Rotation next

  • Continue to Program 26
  • Rows rotate: ABCDE, BCDEA, …

Notes

  • Triangular count. Total letters for n rows is n(n+1)/2 — same as Program 13, hence O(n²) time.
  • Keep code outside the outer loop; use range(rows, 0, -1) for decreasing widths.
  • " ".join(row) avoids trailing spaces; the letter sequence stays identical.
  • Clamp to 6 rows for A–Z demos (21 letters = A through U).

Quick Takeaway: shrinking outer loop picks the width, running code supplies consecutive letters, then break the line — that is the whole pattern.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–2)O(rows²)O(1)
join variant (Example 3)O(rows²)O(row_len) per row for the list
Wrap Up

🎉 Conclusion

The continuous decreasing alphabet triangle merges two skills: a shrinking outer loop and a running counter that never resets. Master the core nested-loop version, then try the join variant for cleaner rows.

Practice the three examples above, then continue to Program 26’s alphabet rotation pattern.

Keep code outside the outer loop, use range(rows, 0, -1), increment per cell, and clamp rows for A–Z demos.

💡 Best Practices

✅ Do

  • Initialize code once before the outer loop
  • Use for row_len in range(rows, 0, -1):
  • Increment code inside the inner loop after each print
  • Clamp rows to 1–6 for A–Z demos
  • State O(n²) time and the triangular letter count when asked

❌ Don’t

  • Reset code = ord('A') on every outer iteration
  • Use range(1, rows + 1) unless you want Program 13’s shape
  • Call print() inside the inner letter loop
  • Ignore the Z boundary for large row counts
  • Confuse this with Program 5’s reset-per-row rule

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print the continuous decreasing triangle the beginner-friendly way.

5
Core concepts
A+ 02

Running char

Never reset between rows

Code
n..1 03

Outer loop

range(rows, 0, -1)

Code
04

print()

Ends each row

I/O
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

Because code is initialized once before the outer loop and incremented after every printed character. The counter never resets, so letters stay consecutive across the whole triangle.
Program 13 grows row width (1, 2, 3, … letters). This pattern shrinks width (n, n−1, …, 1) while using the same running counter — A B C D E then F G H I, not A then B C.
Program 5 also uses decreasing row lengths but resets to A each row (ABCDE, ABCD, ABC, …). Here letters continue: A B C D E, F G H I, J K L, M N, O.
That range yields rows, rows−1, …, 1 — exactly how many letters each row needs, longest first. Program 13 uses range(1, rows + 1) for the opposite (growing) shape.
print(ch, end=" ") stays on the same line with a space after each letter. print() ends the current row after the inner loop finishes.
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.
Use a try/except ValueError around int(input()), or check raw.isdigit() before converting, then clamp rows between 1 and 6 so n(n+1)/2 stays within A–Z for demos.

Did you Know? 🔊

One running counter prints letters continuously while row length shrinks: 5 letters, then 4, 3, 2, 1. Total letters for n rows is still n(n+1)/2 — compare Program 13 (growing rows) and Program 5 (decreasing rows but letters reset each line).

Continue to Alphabet Pattern 26

Next up: alphabet rotation rows (ABCDE, BCDEA, CDEBA, …) with cyclic letter shifts.

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