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 Python Nested For Loop to print the right triangle of numbers from 1 to the maximum value (user-specified rows).

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

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

# Python Program to Print Right Triangle Number Pattern
 
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()

Python 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  

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.