Python X Pattern with Position Numbers (Pattern 93)

Python Code
n = 9  # size
px = n // 2 + 1
for x in range(1, n + 1):
    for y in range(1, n + 1):
        if (y == px or y == n - px + 1):
            print(px, end="")
        else:
            print(" ", end="")
    if (x <= n / 2):
        px -= 1
    else:
        px += 1
    print()

Output:

Output of the Python X Pattern with Position Numbers pattern
BEGINNER WALKTHROUGH

How the X Pattern with Position Numbers works

The X-shaped diagonals are labeled by their moving column position as they travel toward and away from the center.

01

Build the rows

The outer loop creates nine rows, and the middle column position px moves outward on each half of the shape.

02

Choose what each row prints

At either matching diagonal column, the code prints px; the rest of the grid is filled with spaces.

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.