Python X Pattern with Mirrored Numbers (Pattern 92)

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

Output:

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

How the X Pattern with Mirrored Numbers works

The two diagonals form an X and carry row values that increase toward the center, then decrease.

01

Build the rows

The outer loop scans a nine-by-nine grid; px tracks the changing diagonal columns around the center.

02

Choose what each row prints

Only the diagonal cells print p. The value rises in the top half and falls in the bottom half, while other cells print 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.