Pattern Programs · Python example
Use spaces and string repetition to print a centred star pyramid.
Pattern programs combine loops with string repetition. Each row needs the right number of leading spaces and stars.
rows = 5
for row in range(1, rows + 1):
spaces = " " * (rows - row)
stars = "*" * (2 * row - 1)
print(spaces + stars)