Python Right-Aligned Increasing-Number Triangle (Pattern 26)

Python Code
for x in range(1, 6):
    for y in range(5, x, -1):
        print(" ", end="")
    for z in range(1, x + 1):
        print(z, end="")
    print()

Output:

Output of the Python Right-Aligned Increasing-Number Triangle pattern
BEGINNER WALKTHROUGH

How the Right-Aligned Increasing-Number Triangle works

Each row is shifted right and counts from 1 up to its row number.

01

Build the rows

The outer loop increases x from 1 to 5, while the preceding loop prints the spaces needed for alignment.

02

Choose what each row prints

The final inner counter z runs from 1 through x, creating prefixes such as 1, 12, and 123.

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.