To print a hollow inverted pyramid pattern in Python, we use nested loops to manage spaces and stars.
In this example,
def print_hollow_inverted_pyramid(num_rows):
for row in range(num_rows, 0, -1):
pattern = ''
for space in range(0, num_rows - row):
pattern += ' '
if row == num_rows or row == 1:
pattern += '*' * (2 * row - 1)
else:
pattern += '*'
pattern += ' ' * (2 * row - 3)
pattern += '*'
print(pattern)
print_hollow_inverted_pyramid(5)
********* * * * * * * *
In this tutorial, we learned How to print Hollow Inverted Pyramid Pattern in Python language with well detailed examples.