A pattern, row by row
Think of drawing a staircase of # signs on squared paper. Row 1 has one sign, row 2 has two, row 3 has three. You draw one row at a time, and within each row you draw the signs from left to right.
That's two loops again. The outer loop goes through the rows. The inner loop goes through the columns of the current row, and it adds one sign per pass. The inner loop's length can depend on which row you are on.
for row in range(1, n + 1):
for col in range(row):
... # one sign per pass- row
- 1
- line
- #
Row 1: the inner loop runs once, adding one sign. The line is #, which goes into the list.
Build one line, then keep it
A function can't print on squared paper, so we return the picture as a list of strings, one string per row. Make an empty list for the rows. In the outer loop, start an empty string for the current line, and let the inner loop add a sign to it on each pass.
When the inner loop ends, the line is finished, so add it to the list of rows. Start each new line empty, inside the outer loop, or the old signs carry over into the next row.
rows = []
for row in range(1, n + 1):
line = ""
for col in range(row):
line = line + "#"
rows.append(line)