Python Right-Aligned Repeated-Number Triangle (Pattern 25)

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

Output:

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

How the Right-Aligned Repeated-Number Triangle works

The right-aligned rows repeat their row number, growing from one 1 to five 5s.

01

Build the rows

The outer counter x selects both the row number and the number of leading spaces to remove.

02

Choose what each row prints

The first inner loop adds alignment spaces; the second prints x once for every column in the 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.