Write a Python Program to Print Inverted Right Triangle of Numbers using For Loop and While Loop with an example.
Python Program to Print Inverted Right Triangle of Numbers using For Loop
This Python program allows user to enter the total number of rows. Next, we used Python While Loop, and For Loop to print then inverted right triangle of numbers from the maximum value to 1.
# Python Program to Print Inverted Right Triangle of Numbers rows = int(input("Please Enter the total Number of Rows : ")) print("Inverted Right Triangle Pattern of Numbers") i = rows while(i >= 1): for j in range(1, i + 1): print('%d ' %i, end = ' ') i = i - 1 print()
Please Enter the total Number of Rows : 12
Inverted Right Triangle Pattern of Numbers
12 12 12 12 12 12 12 12 12 12 12 12
11 11 11 11 11 11 11 11 11 11 11
10 10 10 10 10 10 10 10 10 10
9 9 9 9 9 9 9 9 9
8 8 8 8 8 8 8 8
7 7 7 7 7 7 7
6 6 6 6 6 6
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
>>>
Python Inverted Right Triangle Program using While Loop
This Python inverted right triangle program is the same as the above. However, in this Python program, we replaced the For Loop with While Loop
# Python Program to Print Inverted Right Triangle of Numbers rows = int(input("Please Enter the total Number of Rows : ")) print("Inverted Right Triangle Pattern of Numbers") i = rows while(i >= 1): j = 1 while(j <= i): print('%d ' %i, end = ' ') j = j + 1 i = i - 1 print()