To print a hollow pyramid pattern in Python, you can use nested loops. The outer loop controls the rows, and the inner loops manage the spaces and stars to create the hollow effect.
In this example,
def print_hollow_pyramid(rows):
for i in range(1, rows + 1):
pattern = ' ' * (rows - i) * 2
for j in range(1, 2 * i):
if j == 1 or j == 2 * i - 1 or i == rows:
pattern += '* '
else:
pattern += ' '
print(pattern)
print_hollow_pyramid(5)
* * * * * * * * * * * * * * * *
In this tutorial, we learned How to print Hollow Pyramid Pattern in Python language with well detailed examples.