Python Program to Print Hollow Left Pascals Star Triangle

Write a Python program to print hollow left pascals star triangle pattern using for loop. 

rows = int(input("Enter Hollow Left Pascals Star Triangle Pattern Rows = "))

print("====Hollow Left Pascals Star Triangle Pattern====")

for i in range(1, rows + 1):
    for j in range(rows, i, -1):
        print(end = ' ')
    for k in range(1, i + 1):
        if k == 1 or k == i:
            print('*', end = '')
        else:
            print(end = ' ')      
    print()

for i in range(1, rows + 1):
    for j in range(1, i + 1):
        print(end = ' ')
    for k in range(rows - 1, i - 1, -1):
        if k == rows - 1 or k == i:
            print('*', end = '')
        else:
            print(end = ' ')
    print()
Python Program to Print Hollow Left Pascals Star Triangle

This Python program prints the hollow left pascals star triangle pattern using a while loop.

rows = int(input("Enter Hollow Left Pascals Star Triangle Pattern Rows = "))

print("====Hollow Left Pascals Star Triangle Pattern====")
i = 1
while(i <= rows):
    j = rows
    while ( j > i):
        print(end = ' ')
        j = j - 1
    k = 1
    while( k <= i):
        if k == 1 or k == i:
            print('*', end = '')
        else:
            print(end = ' ')
        k = k + 1
    print()
    i = i + 1

i = 1
while(i <= rows - 1):
    j = 1
    while(j <= i):
        print(end = ' ')
        j = j + 1
    k = rows - 1
    while(k >= i):
        if k == rows - 1 or k == i:
            print('*', end = '')
        else:
            print(end = ' ')
        k = k - 1
    print()
    i = i + 1
Enter Hollow Left Pascals Star Triangle Pattern Rows = 7
====Hollow Left Pascals Star Triangle Pattern====
      *
     **
    * *
   *  *
  *   *
 *    *
*     *
 *    *
  *   *
   *  *
    * *
     **
      *

In this Python example, we used the pyHollowLeftPascalsStar function to display the hollow left pascals triangle of a given character.

def pyHollowLeftPascalStar(rows, ch):
    for i in range(1, rows + 1):
        for j in range(rows, i, -1):
            print(end = ' ')
        for k in range(1, i + 1):
            if k == 1 or k == i:
                print('%c' %ch, end = '')
            else:
                print(end = ' ')      
        print()

    for i in range(1, rows + 1):
        for j in range(1, i + 1):
            print(end = ' ')
        for k in range(rows - 1, i - 1, -1):
            if k == rows - 1 or k == i:
                print('%c' %ch, end = '')
            else:
                print(end = ' ')
        print()

rows = int(input("Enter Hollow Left Pascals Star Triangle Pattern Rows = "))

ch = input("Symbol to use in Hollow Left Pascals Triangle Pattern = " )

print("====Hollow Left Pascals Triangle Pattern====")
pyHollowLeftPascalStar(rows, ch)
Enter Hollow Left Pascals Star Triangle Pattern Rows = 14
Symbol to use in Hollow Left Pascals Triangle Pattern = #
====Hollow Left Pascals Triangle Pattern====
             #
            ##
           # #
          #  #
         #   #
        #    #
       #     #
      #      #
     #       #
    #        #
   #         #
  #          #
 #           #
#            #
 #           #
  #          #
   #         #
    #        #
     #       #
      #      #
       #     #
        #    #
         #   #
          #  #
           # #
            ##
             #

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.