Pattern Display
* * * * *
* * * *
* * *
* *
*
Implementation
n = 5
for i in range(n, 0, -1): # Outer loop for rows (decreasing order)
for j in range(i): # Inner loop for stars
print("*", end=" ")
print() # Moves to the next line
Steps
Identify the Pattern
- The number of rows (
n
) determines the height of the pattern. - The first row contains
n
stars (*
), and each subsequent row has one less star than the previous.
Looping Strategy
- Use an outer loop to iterate through the rows (
i
fromn
to1
). - Use an inner loop to print
i
stars in each row.
Printing Output
- Print stars on the same line using
end=" "
to maintain spacing. - After finishing one row, move to the next line using
print()
.
Pattern Output
* * * * *
* * * *
* * *
* *
*