Step 01 Beginner Problems — Patterns
Pattern 10 — Half Diamond Star Pattern
Half a diamond, sliced vertically: star counts climb 1, 2, 3, ..., n and then descend n-1, ..., 1, all glued to the left edge. With 2n - 1 rows it is the simplest 'go up, then come down' pattern — one count that changes direction at the peak.
* * * * * * * * * * * * * * * * * * * * * * * * *
How to think about it
Number all rows k = 0, 1, ..., 2n - 2 (that is 2n - 1 rows). The star count is k + 1 while k < n (the climb) and 2n - 1 - k once k >= n (the descent). At the peak row k = n - 1 the count is exactly n, and it appears only once — unlike Pattern 9's doubled widest row. Equivalently, the count is min(k + 1, 2n - 1 - k): the distance-driven minimum of the 'growing' and 'shrinking' formulas. There are no leading spaces; the silhouette comes purely from the count.
Code
A single loop runs over all 2n - 1 rows and picks the count with an if/else: i + 1 on the way up, 2n - 1 - i on the way down. One print statement serves both halves — the direction change lives entirely in the count formula.
def pattern(n):
for i in range(2 * n - 1):
if i < n:
count = i + 1
else:
count = 2 * n - 1 - i
print(" ".join(["*"] * count))Key points
- Rows = 2n - 1; counts run 1, 2, ..., n, ..., 2, 1 with the peak n printed once.
- Count formula: i + 1 while i < n, else 2n - 1 - i — equivalently min(i + 1, 2n - 1 - i).
- Contrast Pattern 9: there the widest row repeats; here the peak appears a single time.
- No space loop at all — the silhouette comes purely from the count.
- Bounds check: range(2n - 1) rows, and the last row must be a single star.