To print a Hollow Diamond Pattern in Python, we use nested loops and conditional statements to manage spaces and stars.
In this example,
# Print Hollow Diamond Pattern in Python
num_rows = 5
for row in range(1, num_rows + 1):
pattern = ' ' * (num_rows - row)
if row == 1:
pattern += '*'
else:
pattern += '*' + ' ' * (2 * row - 3) + '*'
print(pattern)
for row in range(num_rows - 1, 0, -1):
pattern = ' ' * (num_rows - row)
if row == 1 or row == num_rows:
pattern += '*'
else:
pattern += '*' + ' ' * (2 * row - 3) + '*'
print(pattern)
* * * * * * * * * * * * * * * *
In this tutorial, we learned How to print Hollow Diamond Pattern in Python language with well detailed examples.