Decreasing Alphabet Pattern in Python

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

What You’ll Learn

The decreasing alphabet pattern is the mirror of Program 1’s growing triangle: the first row is longest, each line drops one letter at the end. This tutorial covers the shape rule, reverse outer loop, a live preview, algorithm steps, worked Python examples, edge cases, and complexity.

Shape Rule

A..end letter, shrinking rows

Row 1 prints ABCDE (all rows letters), then ABCD, …, down to a single A.

Outer Loop

Rows

for i in range(rows, 0, -1): picks how many letters each row prints — longest first.

Inner Loop

Letters

for code in range(base, base + i): still prints letters from A; only the outer bound i shrinks each row.

print end= vs print()

Same line / next line

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

Live Preview

1–26 rows

Pick a row count and draw the decreasing alphabet pattern instantly in the browser.

O(n²)

Complexity

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

Introduction

A decreasing alphabet pattern starts with the longest row and shortens by one letter each line. With five rows the console shows ABCDE, ABCD, ABC, AB, A — the inverse of Program 1’s growing triangle.

In Python you solve it with two nested for loops: the outer loop walks i from rows down to 1, the inner loop prints letters from A through i characters, then print() moves to the next line.

Why it matters?

It reinforces reverse outer-loop bounds — the same inner letter logic as Program 1, flipped. Once range(rows, 0, -1) clicks, inverted stars, numbers, and more patterns follow naturally.

Key Highlights

Row = Shrinking Length

On row i, print i letters from A; first row has rows letters.

Reverse Outer Loop

range(rows, 0, -1) walks longest row first.

print Then Break

print(chr(code), end="") in the inner loop; print() after.

Program 1 Mirror

Same inner loop; only outer direction differs from the increasing triangle.

In short: for each row i from rows down to 1, print letters from A with print(chr(code), end=""), then call print().

📝 Problem & Approach

Given a positive integer rows, print a left-aligned decreasing alphabet pattern: the first line has rows letters from A, each next line one fewer, ending with A.

Python
# First 5 rows (conceptual shape)
# ABCDE
# ABCD
# ABC
# AB
# A

Inputs & Outputs

ItemTypeDescription
rowsintNumber of triangle lines to print (typically ≥ 1).
Printed outputtextLeft-aligned rows of letters; first row has rows letters from A, each row one shorter.

Minimal workflow

Pseudocode
for i from rows down to 1:
    for j from 1 to i:
        print next letter from A (no newline)
    print newline

Approach comparison

ApproachIdeaBest for
Nested loopsDecreasing outer + inner letters from ALearning and interviews
Reverse outer loopfor i in range(rows, 0, -1)Decreasing row lengths — this pattern
letters[:i]Slice first i letters with decreasing iShorter production-style demos

⚡ Quick Reference

GoalPattern
Walk each row (decreasing)for i in range(rows, 0, -1):
Print A..end lettersfor code in range(base, base + i): print(chr(code), end="")
End the rowprint()
One-line row shortcutprint(letters[:i]) inside decreasing outer loop
Growing variantUse range(1, rows + 1) — see Program 1

📋 print end= vs print() vs slice

Same decreasing pattern — different ways to emit characters.

print(..., end="")
same line

Prints a letter without moving to the next line

print()
new line

Ends the current row after all letters are printed

letters[:i]
whole row

Builds letters A..end at once — skip the inner loop

Learning tip
loops first

Master nested loops before the string shortcut

Context

When This Pattern Shows Up

Reach for this pattern when teaching reverse outer loops or mirroring Program 1’s growing triangle.

  1. Reverse-loop practice

    Natural follow-up after Program 1 — same inner logic, outer loop counts down.

  2. Nested-loop warm-up

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

  3. CLI I/O practice

    Combine loops with input() for a flexible row count.

  4. Gateway to variants

    Leads to left-trim patterns, pyramids, and hollow shapes in the series.

  5. Not a UI layout tool

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

Key benefit: one small program that locks in reverse outer loops, output sequencing, and O(n²) thinking — the mirror image of Program 1.

🔮 Live Preview

Choose a row count between 1 and 20 and draw the decreasing alphabet pattern in the browser.

Try 5, 7, or 10. Cap is 26 letters (A–Z).

Live result
Press "Draw pattern".

Examples Gallery

Three complete Python programs — fixed row count, CLI input, and a letters[:i] shortcut. Click View Output to reveal sample console results.

📚 Getting Started

Print five rows with classic nested loops — longest row first.

Example 1 — Fixed rows = 5

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

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

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

How It Works

When i = 5, the inner loop prints ABCDE. When i = 4, it prints ABCD, and so on until i = 1 prints a single A. print() after the inner loop starts the next row.

📈 Practical Variant

Let the user choose the height at runtime.

Example 2 — User Input Version

Read the row count with input() and convert with int() (wrap in try/except ValueError in real apps).

Python
rows = int(input("Enter the number of rows (max 26): "))
rows = max(1, min(rows, 26))
base = ord('A')
for i in range(rows, 0, -1):
    for code in range(base, base + i):
        print(chr(code), end="")
    print()

How It Works

Same ord/chr core as Example 1; only the source of rows changes. The outer loop still counts down from the clamped value. Non-numeric input raises ValueError with bare int(input()) — use try/except for safer labs.

⚡ Shortcut Style

Same shape without an explicit inner letter loop.

Example 3 — letters[:i]

Slice A–Z for each shrinking row length with letters[:i] inside a decreasing outer loop.

Python
rows = 5
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(rows, 0, -1):
    print(letters[:i])

How It Works

letters[:i] returns the first i letters of the alphabet. With i counting down from rows, you get the same ABCDE-to-A shape without an explicit inner loop. Keep the two-loop version for exams that ask you to show both bounds.

🧠 How the Algorithm Prints Rows

1

Set up

Use input() when reading input. Set rows (fixed or from CLI) and clamp to 1–26 for A–Z.

Setup
2

Outer loop (rows, decreasing)

for i in range(rows, 0, -1): selects how many letters the current line prints — longest first.

Row
3

Inner loop (letters)

for code in range(base, base + i): prints each letter with print(chr(code), end="").

Letters
4

New line

print() ends the row so the next outer iteration starts fresh.

Break
=

Decreasing alphabet pattern complete

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

🔎 Worked Walkthrough — rows = 4

Trace each outer-loop value i (counting down) and see what the inner loop prints from A.

Outer iInner code rangePrinted rowLetters this row
4A..DABCD4
3A..CABC3
2A..BAB2
1A..AA1

Total letter prints: 4 + 3 + 2 + 1 = 10 = 4×5/2. Same triangular total as Program 1 — only row order differs.

Use Cases

Where this shrinking letter pattern (and its reverse outer loop) shows up beyond the homework prompt.

1. Teaching Reverse Loops

Clearest visual proof that range(rows, 0, -1) shrinks row length each iteration.

Example: compare side-by-side with Program 1.

2. Pattern Series Bridge

Natural step after Program 1 before left-trim and pyramid letter patterns.

Example: Program 6 shifts the start letter each row.

3. Console Formatting Drills

Practice character loops and print(..., end="")/print() with a shape that differs visibly from Program 1.

Example: swap outer loop direction and compare outputs.

4. Character Substitution

Swap to lowercase or digits once the letter loop works.

Example: print lowercase a..z once uppercase clicks.

5. Complexity Intuition

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

Example: count printed letters for n = 10 → 55.

6. Input Validation Labs

Pair the pattern with try/except ValueError and positive-row checks.

Example: reject rows <= 0 and re-prompt.

Pro Tip: when an interviewer asks for the decreasing variant, explain that only the outer loop changes — inner letter logic matches Program 1.

Advantages

Why this decreasing pattern earns a spot after Program 1 in beginner Python courses.

  1. 1. Instant Visual Contrast

    Side-by-side with Program 1 makes reverse outer loops obvious.

  2. 2. Minimal Concepts

    Only loops and console output — no arrays or math libraries.

  3. 3. Easy to Compare

    One-line outer-loop change flips between growing and shrinking shapes.

  4. 4. O(1) Extra Memory

    Streaming output needs no storage beyond loop counters.

Pro Tip: master Program 1 first, then this page — the inner loop is identical; only range(rows, 0, -1) is new.

Usage Tips

Small habits that keep decreasing alphabet-pattern code clean.

  1. 1. Name Bounds Clearly

    Use rows (or n) and keep i/j for row/column — or rename to row/col.

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

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

  3. 3. Keep print() Outside

    Only call print() after the inner loop finishes the row.

  4. 4. Use Decreasing Outer Loop

    range(rows, 0, -1) matches “first row longest, each row one shorter” naturally.

  5. 5. Dry-Run One Small n

    Trace rows = 3 on paper — expect ABC, AB, A — before coding larger demos.

Pro Tip: if the output is a vertical list of single letters, you almost certainly put print() inside the inner loop.

Common Pitfalls

Mistakes that commonly break decreasing alphabet patterns.

  1. 1. print() Inside the Inner Loop

    Each letter lands on its own line — you get a column, not a shrinking row pattern.

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

  2. 2. Wrong Outer Loop Direction

    range(1, rows + 1) prints Program 1’s growing triangle, not ABCDE-to-A.

    → For this shape, use range(rows, 0, -1).

  3. 3. Forgetting the Row Break

    Omitting print() after the inner loop glues every letter onto one endless line.

    → Always end the row after the inner loop.

  4. 4. Blind int(input())

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

    → Wrap in try/except ValueError and validate range.

  5. 5. Confusing with Program 1

    Copying Program 1’s outer loop produces A, AB, ABC — the opposite shape.

    → Decreasing pattern: outer counts down; inner still uses range(base, base + i).

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single letter last row

Output ends with just A on the last line.

rows = 0

Empty pattern

Outer loop never runs — print nothing or show a message.

Negative

rows < 0

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

Large n

Many rows

Output grows as n²/2 characters — fine for labs, noisy for huge n.

Bad input

Non-numeric input

int(input()) raises ValueError — validate first.

Fill char

Not only uppercase

Same loops work with #, digits, or letters.

🎯 Practice Problems

Try these variations to lock in the decreasing pattern.

1. Flip to increasing

  • Outer loop from 1 to rows
  • Compare with Program 1

2. Print digits instead

  • Replace chr(code) with digit logic
  • Same shrinking outer loop structure

3. Safe input loop

  • Use try/except ValueError until rows >= 1
  • Then draw the decreasing pattern

4. Continue the series

  • Try Program 6 — left-trim each row
  • Next step after ABCDE-to-A

Notes

  • Triangular count. Total letters for n rows is still n(n+1)/2 — same as Program 1, only row order differs.
  • print(..., end="") stays on the line; print() advances — mix them carefully.
  • Validate rows > 0 for interactive programs; rows = 1 should print a single A (one row only).
  • This page shrinks from the top. Program 1 grows from the bottom — compare both to see how outer-loop direction drives the shape.

Quick Takeaway: outer loop counts down from rows, inner loop prints A..end, then break the line — mirror of Program 1.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–2)O(rows²)O(1)
letters[:i] (Example 3)O(rows²)O(rows) per row string (temporary)
Wrap Up

🎉 Conclusion

The decreasing alphabet pattern is a compact reverse-loop exercise with lasting payoff: range(rows, 0, -1), the same inner letter logic as Program 1, and O(n²) intuition. Master the classic two-loop version, then optionally shorten rows with letters[:i] inside the decreasing outer loop.

Practice the three examples above, then continue to Program 6 for the next left-trim variant in the series.

First row has rows letters — keep print(..., end="") for letters and print() for the break, and validate row counts when reading input.

💡 Best Practices

✅ Do

  • Explain outer = shrinking row length (rows down to 1), inner = A..end codes
  • Use for i in range(rows, 0, -1): for the decreasing outer loop
  • Use print(chr(code), end="") for letters and print() after each row
  • Validate rows ≥ 1 for interactive programs
  • Wrap int(input()) in try/except ValueError
  • State O(n²) time when asked about complexity

❌ Don’t

  • Call print() inside the inner letter loop
  • Use range(1, rows + 1) when you meant the decreasing pattern
  • Skip the newline after each row
  • Ignore bad console input in user-facing demos
  • Skip the rows = 1 edge case

Key Takeaways

Knowledge Unlocked

Five things to remember about this decreasing pattern

Print ABCDE-to-A the beginner-friendly way.

5
Core concepts
02

Outer loop

range(rows, 0, -1)

Code
A 03

Inner loop

Prints A..end with print

Code
04

print()

Ends each row

I/O
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

The outer loop walks i from rows down to 1, so the first row is longest. The inner loop prints letters from ord('A') through i characters: ABCDE, then ABCD, then ABC, and so on until A.
That range yields rows, rows-1, ..., 1 — exactly how many letters each row needs. Program 1 uses range(1, rows + 1) for the opposite (growing) shape.
print(chr(code), end="") stays on the same line. print() ends the current line. Letters use end=""; the row break uses print() after the inner loop.
Program 1 grows each row (A, AB, ABC). This pattern shrinks: the first row has rows letters from A, each next row drops the last letter. Only the outer loop direction changes — inner letter logic stays the same.
O(n²) where n is the number of rows. Total printed characters still equal n+(n-1)+...+1 = n(n+1)/2 — same triangular count as the increasing triangle.
Yes. Keep letters = "ABCDEFG..." and print(letters[:i]) inside for i in range(rows, 0, -1). Nested ord/chr loops teach the bounds; slicing is a compact shortcut.
Use try/except ValueError around int(input()), or validate with raw.isdigit(), then clamp rows between 1 and 26 so letter codes stay within A–Z.
Letter codes walk past Z and print unexpected characters. Clamp to 26 for A–Z demos, or define a clear error/wrap policy.

Did you Know? 🔊

Row i prints letters from A through the i-th letter, with i shrinking each row: ABCDE, ABCD, …, A. Total letters for n rows is still n(n+1)/2O(n²).

Continue to Program 6

Shift the start letter each row for the next alphabet pattern in the series.

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