Python Program to Print Right Triangle Number Pattern

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 Program to Print Right Triangle Number Pattern

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 For Loop with While Loop

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

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