Write a Python Program to Print Hollow Inverted Right Triangle using for loop. The first for loop (for i in range(rows, 0, -1)) iterate from rows to 0, and for j in range(i, 0, -1) iterate from i to 0. The if statement check i equal zero, rows, j or j equals one value, and if true, print stars.
# Python Program to Print Hollow Inverted Right Triangle Star Pattern rows = int(input("Enter Hollow Right Inverted Triangle Rows = ")) print("Hollow Inverted Right Triangle Star Pattern") for i in range(rows, 0, -1): for j in range(i, 0, -1): if i == 1 or i == rows or j == 1 or j == i: print('*', end = '') else: print(' ', end = '') print()
This Python Program uses a while loop to print Hollow Inverted Right Triangle.
# Python Program to Print Hollow Inverted Right Triangle Star Pattern rows = int(input("Enter Hollow Right Inverted Triangle Rows = ")) print("Hollow Inverted Right Triangle Star Pattern") i = rows while(i > 0): j = i while(j > 0): if i == 1 or i == rows or j == 1 or j == i: print('*', end = '') else: print(' ', end = '') j = j - 1 i = i - 1 print()
Enter Hollow Right Inverted Triangle Rows = 12
Hollow Inverted Right Triangle Star Pattern
************
* *
* *
* *
* *
* *
* *
* *
* *
* *
**
*
>>>
In this Python example, we created a hollowInvertedRightTriangle function to print the hollow Inverted Right angled Triangle. It replaces the star in a hollow inverted Right Triangle with the given symbol.
# Python Program to Print Hollow Inverted Right Triangle Star Pattern def hollowInvertedRightTriangle(rows, ch): for i in range(rows, 0, -1): for j in range(i, 0, -1): if i == 1 or i == rows or j == 1 or j == i: print('%c' %ch, end = '') else: print(' ', end = '') print() rows = int(input("Enter Hollow Inverted Right Triangle Rows = ")) ch = input("Symbol to use in Hollow Inverted Right Triangle = ") print("Hollow Inverted Right Triangle Pattern") hollowInvertedRightTriangle(rows, ch)
Enter Hollow Inverted Right Triangle Rows = 15
Symbol to use in Hollow Inverted Right Triangle = #
Hollow Inverted Right Triangle Pattern
###############
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
##
#
>>>