Print Number Pattern

Print a basic right-angled triangle number pattern using nested loops.

PythonBeginner
Python
# Program to print a right-angled number triangle

rows = int(input("Enter number of rows: "))

for i in range(1, rows + 1):
    for j in range(1, i + 1):
        print(j, end=" ")
    print()

Output

Enter number of rows: 4
1 
1 2 
1 2 3 
1 2 3 4 

We use nested loops: the outer loop controls rows and the inner loop prints numbers from 1 up to the row index.