Python Inward V Row-Number Pattern (Pattern 87)

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

Output:

Output of the Python Inward V Row-Number Pattern pattern
BEGINNER WALKTHROUGH

How the Inward V Row-Number Pattern works

The inward-moving diagonal arms show 1 through 5 according to their current row.

01

Build the rows

The outer loop counts upward through five rows, while the inner loop checks every column in the wide grid.

02

Choose what each row prints

Matching diagonal positions print x; the left marker moves right and the right marker moves left after each row.

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.