Write a Python Program to Print Right Triangle Number Pattern using For Loop and While Loop with example.
Python Program to Print Right Triangle Number Pattern using For Loop
This Python program allows user to enter the total number of rows. Next, we used the Nested For Loop to print the right triangle of numbers from 1 to the maximum value (user-specified rows).
rows = int(input("Please Enter the total Number of Rows : "))
print("Right Triangle Pattern of Numbers")
for i in range(1, rows + 1):
for j in range(1, i + 1):
print('%d' %i, end = ' ')
print()

Python Right Triangle Program using While Loop
This Python right triangle of numbers program is the same as the above. However, in this Python program, we replaced the Python nested for Loop with Python While syntax
rows = int(input("Please Enter the total Number of Rows : "))
print("Right Triangle Pattern of Numbers")
i = 1
while(i <= rows):
j = 1
while(j <= i):
print('%d' %i, end = ' ')
j = j + 1
i = i + 1
print()
Right Triangle Number Pattern output. For more patterns, please refer to the Python Number pattern programs.
Please Enter the total Number of Rows : 10
Right Triangle Pattern of Numbers
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
10 10 10 10 10 10 10 10 10 10
Also Read
- Python Program to Print Hollow Box Pattern of Numbers
- Python Program to Print Right Triangle of 1 and 0