Step 01 Beginner Problems — Patterns
Pattern 8 — Inverted Star Pyramid
The star pyramid of Pattern 7 standing on its head: the first row is the full base of 2n - 1 stars and each row below sheds two stars — one from each side — until a single star remains at the bottom tip. The leading spaces grow exactly as fast as the stars shrink.
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
How to think about it
Number the rows i = 0, 1, ..., n-1. Row i prints i blank slots followed by 2(n - i) - 1 stars. At i = 0: no blanks, 2n - 1 stars. At i = n - 1: n - 1 blanks and exactly 1 star. The star formula 2(n - i) - 1 is just Pattern 7's 2i + 1 run backwards, and the blank count i is Pattern 7's shrinking blank count run forwards. Symmetry around the same center column is preserved on every row.
Code
Each row is ' ' * i for the indent (two characters per empty slot, matching the token width) plus 2(n - i) - 1 joined '*' tokens. The two quantities are computed from the same i, so the rows narrow and drift right in lockstep.
def pattern(n):
for i in range(n):
indent = " " * i
stars = " ".join(["*"] * (2 * (n - i) - 1))
print(indent + stars)Key points
- Row i: blanks = i, stars = 2(n - i) - 1.
- Widths step down through the odd numbers: 2n-1, 2n-3, ..., 1.
- It is Pattern 7 with both formulas reversed — learn one, derive the other.
- The final row is n - 1 blank slots and a single star, sitting on the center column.
- Off-by-one trap: 2(n - i) - 1, not 2(n - i) + 1 — test with n = 1, which must print a single star.