Pattern problems ask you to print a 2D shape out of characters. The one idea that unlocks all of them: an outer loop picks the row, an inner loop fills that row's columns. Nested loops draw a grid.
For an N×N square of stars, the outer loop runs N times (one per row); for each row the inner loop runs N times, appending a star:
row 1: * * * * (inner loop ran 4 times)
row 2: * * * *
row 3: * * * *
row 4: * * * *
The output is multiple lines, so these problems return lines — you build each row as a
string and join the rows with a newline ("\n"). The starter prints exactly what you return.
def solve(n):
rows = []
for r in range(n): # outer loop: one iteration per row
row = ""
for c in range(n): # inner loop: fill this row's columns
row += "*"
rows.append(row)
return "\n".join(rows) # join rows into the final multi-line output
Fix this skeleton in your mind. Every other pattern is a tweak to what the inner loop does or how far it runs.