Home ยป Display a Sandglass Star Pattern using python

Display a Sandglass Star Pattern using python

In this article we display a sandglass pattern using python

Code

rows = int(input("Enter amount of Rows = "))

print("====Pattern====")

for i in range(0, rows):
    for j in range(0, i):
        print(end = ' ')
    for k in range(i, rows):
        print('*', end = ' ')                
    print()

for i in range(rows - 1, -1, -1):
    for j in range(0, i):
        print(end = ' ')
    for k in range(i, rows):
        print('*', end = ' ')      
    print()

When you run this you would see something like this

Alternative

def drawSandglass(rows, ch):
    for i in range(0, rows):
        for j in range(0, i):
            print(end = ' ')
        for k in range(i, rows):
            print('%c' %ch, end = ' ')               
        print()

    for i in range(rows - 1, -1, -1):
        for j in range(0, i):
            print(end = ' ')
        for k in range(i, rows):
            print('%c' %ch, end = ' ')     
        print()
    
rows = int(input("Enter amount of Rows = "))

char = input("Symbol to use = " )

print("====Pattern====")
drawSandglass(rows, char)

 

Link

sandglasspattern1

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More