Print Inverted Pyramid Pattern in Python

Print an inverted centered pyramid of stars.

BeginnerLoop ProgramsExample 23 of 25
print-inverted-pyramid-pattern.py
Run in browser
1# Program to print an inverted pyramid star pattern
2
3rows = int(input("Enter number of rows: "))
4
5for i in range(rows, 0, -1):
6 spaces = " " * (rows - i)
7 stars = "*" * (2 * i - 1)
8 print(spaces + stars)

Output

Enter number of rows: 3
*****
 ***
  *

What's going on

We reverse the logic of the normal pyramid, starting from the widest row and decreasing.