Python Right-Aligned Star Triangle (Pattern 24)

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

# Another Logic

for x in range(1, 6):
    for y in range(5, 0, -1):
        if x >= y:
            print("*", end="")
        else:
            print(" ", end="")
    print()

Output:

Output of the Python Right-Aligned Star Triangle pattern
BEGINNER WALKTHROUGH

How the Right-Aligned Star Triangle works

Leading spaces shift each growing row of stars to the right, creating a staircase-shaped triangle.

01

Build the rows

The outer loop grows x from 1 to 5. A first inner loop prints fewer leading spaces as the row gets longer.

02

Choose what each row prints

A second inner loop prints x stars, then the line break starts the next 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.