Python Top-Down V Position-Number Pattern (Pattern 83)

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

Output:

Output of the Python Top-Down V Position-Number Pattern pattern
BEGINNER WALKTHROUGH

How the Top-Down V Position-Number Pattern works

The widening V uses its moving left diagonal position as the number printed on both arms.

01

Build the rows

The outer loop creates five rows, and px and py move away from the center after every line.

02

Choose what each row prints

The inner condition prints px only at either diagonal column; all other columns receive a space.

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.