Short Python Program to Print Inverted Right Triangle of Numbers

Posted by

Python Program to Print Inverted Right Triangle of Numbers

Python Program to Print Inverted Right Triangle of Numbers

Here is a simple Python program that prints an inverted right triangle of numbers:

“`python
# Python program to print inverted right triangle of numbers

rows = 5

for i in range(0, rows):
for j in range(0, i + 1):
print(i + 1, end=’ ‘)
print(“r”)
“`

When you run this program, it will output the following inverted right triangle of numbers:

5 
4 4 
3 3 3 
2 2 2 2 
1 1 1 1 1 

This program uses nested loops to print the inverted right triangle of numbers. The outer loop iterates over the rows, while the inner loop prints the numbers in each row. The `end=’ ‘` parameter in the print statement is used to avoid printing a new line after each number.

Feel free to play around with the program and try different values for the `rows` variable to see how the output changes.