Python program to Print Sandglass Star Pattern

Write a Python program to print the sandglass star pattern using for loop. 

rows = int(input("Enter Sandglass Star Pattern Rows = "))

print("====Sandglass Star 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()
Python program to Print Sandglass Star Pattern

This Python program prints the sandglass star pattern using a while loop.

rows = int(input("Enter Sandglass Star Pattern Rows = "))

print("====Sandglass Star Pattern====")
i = 0
while(i <= rows - 1):
    j = 0
    while(j < i):
        print(end = ' ')
        j = j + 1
    k = i
    while(k <= rows - 1):
        print('*', end = ' ')
        k = k + 1
    print()
    i = i + 1

i = rows - 1
while(i >= 0):
    j = 0
    while(j < i):
        print(end = ' ')
        j = j + 1
    k = i
    while(k <= rows - 1):
        print('*', end = ' ')
        k = k + 1
    print()   
    i = i - 1
Enter Sandglass Star Pattern Rows = 7
====Sandglass Star Pattern====
* * * * * * * 
 * * * * * * 
  * * * * * 
   * * * * 
    * * * 
     * * 
      * 
      * 
     * * 
    * * * 
   * * * * 
  * * * * * 
 * * * * * * 
* * * * * * * 

In this Python example, we used the pySandglassStar function to display the sandglass pattern of a given character.

def pySandglassStar(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 Sandglass Star Pattern Rows = "))

ch = input("Symbol to use in Sandglass Pattern = " )

print("====Sandglass Pattern====")
pySandglassStar(rows, ch)
Enter Sandglass Star Pattern Rows = 12
Symbol to use in Sandglass Pattern = $
====Sandglass Pattern====
$ $ $ $ $ $ $ $ $ $ $ $ 
 $ $ $ $ $ $ $ $ $ $ $ 
  $ $ $ $ $ $ $ $ $ $ 
   $ $ $ $ $ $ $ $ $ 
    $ $ $ $ $ $ $ $ 
     $ $ $ $ $ $ $ 
      $ $ $ $ $ $ 
       $ $ $ $ $ 
        $ $ $ $ 
         $ $ $ 
          $ $ 
           $ 
           $ 
          $ $ 
         $ $ $ 
        $ $ $ $ 
       $ $ $ $ $ 
      $ $ $ $ $ $ 
     $ $ $ $ $ $ $ 
    $ $ $ $ $ $ $ $ 
   $ $ $ $ $ $ $ $ $ 
  $ $ $ $ $ $ $ $ $ $ 
 $ $ $ $ $ $ $ $ $ $ $ 
$ $ $ $ $ $ $ $ $ $ $ $