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 browser1# Program to print a right-angled number triangle23rows = int(input("Enter number of rows: "))45for 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.