Step 01 Beginner Problems — Patterns
Pattern 1 — Rectangular Star Pattern
A solid block of stars: n rows and n columns forming a perfect square of '*'. It is the simplest pattern of all — the outer loop and the inner work both repeat exactly n times — and it teaches the one idea every pattern in this series is built on: one loop controls the rows, the other controls what each row contains.
* * * * * * * * * * * * * * * * * * * * * * * * *
How to think about it
Number the rows i = 0, 1, ..., n-1. Every row is identical: it contains exactly n stars and no leading spaces, so the outer loop simply repeats n times and the inner work for each row is 'print n stars'. If you build the row as a list of n '*' tokens and join them with single spaces, every row comes out as '* * * ... *' with n stars and n-1 gaps between them. There is no per-row formula to vary — the constancy is the point: the row content does not depend on i at all. Total output size is n rows x n stars = n*n stars.
Code
The function builds each row by repeating the '*' token n times in a list and joining with spaces, then prints it. The loop variable i only counts rows — it plays no role in the content. Building the row string first (instead of printing token by token) makes the row-by-row structure visible and avoids stray trailing spaces.
def pattern(n):
for i in range(n):
row = " ".join(["*"] * n)
print(row)Key points
- Outer loop = rows (always n of them); inner work = the contents of one row.
- Row content here is independent of the row index i — the same n stars every time.
- Joining a token list with ' ' gives clean spacing with no trailing space.
- Total stars printed is n * n — this is the 'full grid' every hollow pattern later carves into.
- Off-by-one check: range(n) gives exactly n rows, and ['*'] * n gives exactly n stars.