A2Z Lesson

Log in
← Back to the A2Z sheet

Step 01 Beginner Problems — Patterns

Pattern 2 — Right-Angled Triangle Pattern

Easy

A flight of stairs made of stars: the first row has 1 star and every row below it has one more, ending with n stars on the last row. This is the archetypal growing triangle — the first pattern where what a row contains depends on which row it is.

*
* *
* * *
* * * *
* * * * *
Output for n = 5

How to think about it

Number the rows from the top as i = 0, 1, ..., n-1. Row i contains exactly i + 1 stars and no leading spaces — that single formula, stars = i + 1, is the whole pattern. The outer loop walks i from 0 to n-1; for each row you print i + 1 star tokens joined by spaces. The last row (i = n - 1) has n stars, so the triangle's base is exactly as wide as the full n-by-n rectangle of Pattern 1, and the running total of stars is 1 + 2 + ... + n = n(n+1)/2.

Code

For each row index i the code creates a list of i + 1 '*' tokens and prints them joined by spaces. No indent is needed because the triangle is left-aligned — all the growth happens on the right edge.

def pattern(n): for i in range(n): print(" ".join(["*"] * (i + 1)))

Key points

  • Master formula: row i (0-based) prints i + 1 stars.
  • Left-aligned patterns need no space loop — growth is purely in the token count.
  • The base row always has exactly n stars; check your last line when debugging.
  • Using 1-based rows instead? Then row r prints r stars — same thing, just shifted bookkeeping.
  • This 'count grows with i' idea recurs in Patterns 3, 4, 10, 13, 14 and 16.

Suggested questions

Pattern 5 — Inverted Right Pyramid Run this triangle in reverse — the count falls as n - i, the mirror skill.
Pattern 3 — Right-Angled Number Pyramid Same growing counts, but the tokens become the numbers 1..i+1 instead of stars.
Pattern 10 — Half Diamond Star Pattern Grow the triangle, then shrink it back — combines this with its inverse in one figure.
Sum of First N Numbers ↗ Row lengths 1, 2, 3, ..., n add up to a triangular number — this computes that total.

Source note: this lesson follows the structure of Striver's public A2Z DSA course (takeUforward). Each problem links to its original platform, and all problems and content belong to their respective owners — STUDY-BUDDY does not claim ownership of the sheet or its problems, and no permission beyond public linking is claimed.