Small Python For Beginners to Practice |
In this article, we are going to print a Sandglass star pattern using Python as you can see in the featured image.
If you are looking for a Python Tutorial Series then it's here
If you look closely then this Hourglass pattern is a combination of a normal pyramid and inverted pyramid program in Python. So we will combine both of these programs to print out the Hourglass star pattern.
def glass(rows):
spaces = 0
stars2 = 3
spaces2 = rows-2
stars = 2*rows-1
for i in range(1, rows+1):
print(' ' * spaces + '*' * stars)
stars -=2
spaces +=1
for i in range(1, rows):
print(' '*spaces2 + '*'*stars2)
stars2 += 2
spaces2 -= 1
glass(10)
The output of the program is:
*******************
*****************
***************
*************
***********
*********
*******
*****
***
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
Comments
Post a Comment