Printing hollow diamond in python

Harshit Singh
1 min readApr 17, 2023

--

Today, we will explore how to print a hollow diamond pattern using Python. We will break down the logic behind the pattern and provide step-by-step instructions to help you recreate this interesting shape in your Python code.

#printing hollow diamond

# printing upper part of diamond

n = 5
for i in range (0,n):
for j in range(n-i):
print("*", end ="") #printing half of stars for all rows
for k in range(2*i):
print(" ", end = "")# printing spacec for all rows
for l in range(n-i):
print("*", end ="") #printing other half of stars for all rows
print()

#priting lower part of diamond

for a in range(1,n+1):
for b in range(a):
print("*", end = "") #printing half of stars for all rows
for c in range(2*(n-a)):
print(" ", end = "") # printing spacec for all rows
for d in range (a):
print("*", end ="") #printing other half of stars for all rows
print()
Output: Printing hollow diamond in python

--

--

Harshit Singh

Aspiring Data Analyst, MS- Excel, Python, SQL, Learning Technology, Introvert, helping community.