Python Top-Down V Number Pattern (Pattern 82)

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(x, end="")
        else:
            print(" ", end="")
    px -= 1
    py += 1
    print()

Output:

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

How the Top-Down V Number Pattern works

The two widening diagonals display their row number, while spaces fill the rest of each line.

01

Build the rows

The outer loop counts rows from 1 to 5, and the inner loop checks each of the eleven columns.

02

Choose what each row prints

When a column matches px or py, the code prints x; after each line those markers move outward to form a V.

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.