Python Centered Star Pyramid (Pattern 34)

Python Code
inc = 1
for x in range(5, 0, -1):
    for y in range(x, 0, -1):
        print(" ", end="")
    print("*" * inc)
    inc += 2;

Output:

Output of the Python Centered Star Pyramid pattern
BEGINNER WALKTHROUGH

How the Centered Star Pyramid works

Five centered rows contain 1, 3, 5, 7, and 9 stars.

01

Build the rows

The outer loop runs from the top row toward the base; its first inner loop prints one fewer leading space per row.

02

Choose what each row prints

The inc counter starts at 1 and grows by 2 after each row, creating the odd star counts of a pyramid.

03

Keep the output aligned

The inner print calls use end="" to keep values on the same line. The final empty print() moves to the next row.