This Python program reads the number of rows n from the user.
It then prints a triangle of increasing numbers, aligned to the right, where each row contains one more number than the previous.
rows = int(input("Enter number of rows: "))
num = 1
for i in range(1, rows + 1):
print(" " * (rows - i), end="") # spacing for alignment
for j in range(i):
print(f"{num} ", end="")
num += 1
print()
1
2 3
4 5 6
- The outer loop runs from 1 to rows
- Each row starts with spaces to align the triangle
- The inner loop prints i numbers, incrementing num each time
- The result is a clean, right-aligned triangle of sequential numbers