Python Centered Number-Value Pyramid (Pattern 45)

Python Code
for x in range(1, 5):
    for y in range(4, x, -1):
        print(" ", end="")
    for z in range(x - 1, -x, -1):
        print(x - abs(z), end="")
    print()

Output:

Output of the Python Centered Number-Value Pyramid pattern
BEGINNER WALKTHROUGH

How the Centered Number-Value Pyramid works

The rows widen to an odd count and mirror values around their row number, for example 1, 121, and 12321.

01

Build the rows

The outer loop controls four rows, and its companion loop prints the spaces needed to center each one.

02

Choose what each row prints

The z counter moves across the row in both directions; x - abs(z) produces the matching values on either side.

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.