Print Number Pattern in Python

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

BeginnerLoop ProgramsExample 16 of 25
print-number-pattern.py
Run in browser
1# Program to print a right-angled number triangle
2
3rows = int(input("Enter number of rows: "))
4
5for i in range(1, rows + 1):
6 for j in range(1, i + 1):
7 print(j, end=" ")
8 print()

Output

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

What's going on

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