Python Program to Print Hollow Mirrored Half Diamond Star Pattern

Write a Python Program to Print Hollow Mirrored Half Diamond Star Pattern using a for loop, while loop, and functions. This example uses the nested for loop to iterate and print the Hollow Mirrored Half Diamond Stars pattern.

rows = int(input("Enter Hollow Mirrored Half Diamond Pattern Rows = "))

print("Hollow Mirrored Half Diamond Star Pattern") 

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

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

Output.

Python Program to Print Hollow Mirrored Half Diamond Star Pattern using for loop

This Python program uses the while loop to print the Hollow Mirrored Half Diamond Star Pattern. We replaced the above for loop with a while loop.

rows = int(input("Enter Hollow Mirrored Half Diamond Pattern Rows = "))

print("Hollow Mirrored Half Diamond Star Pattern")

i = 1
while i <= rows:
    j = 1
    while j <= rows - i:
        print(' ', end = '')
        j = j + 1
    k = 1
    while k <= i:
        if i == k or k == 1:
            print('*', end = '')
        else:
            print(' ', end = '')
        k = k + 1
    i = i + 1
    print()

i = rows - 1
while i > 0:
    j = 1
    while j <= rows - i:
        print(' ', end = '')
        j = j + 1
    k = 1
    while k <= i:
        if i == k or k == 1:
            print('*', end = '')
        else:
            print(' ', end = '')
        k = k + 1
    i = i- 1
    print() 

Output

Enter Hollow Mirrored Half Diamond Pattern Rows = 13
Hollow Mirrored Half Diamond Star Pattern
            *
           **
          * *
         *  *
        *   *
       *    *
      *     *
     *      *
    *       *
   *        *
  *         *
 *          *
*           *
 *          *
  *         *
   *        *
    *       *
     *      *
      *     *
       *    *
        *   *
         *  *
          * *
           **
            *

In this Python example, we created a HollowMirroredHalfD function that accepts the rows, i value, and characters to Print the Hollow Mirrored Half Diamond Pattern. It replaces the star in the hollow mirrored half diamond pattern with a given symbol.

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

rows = int(input("Enter Hollow Mirrored Half Diamond Rows = "))

ch = input("Symbol in Hollow Mirrored Half Diamond Pattern = ")

for i in range(1, rows + 1):
    HollowMirroredHalfD(rows, i, ch)
        
for i in range(rows - 1, 0, -1):
    HollowMirroredHalfD(rows, i, ch)

Output

Enter Hollow Mirrored Half Diamond Rows = 14
Symbol in Hollow Mirrored Half Diamond Pattern = #
             #
            ##
           # #
          #  #
         #   #
        #    #
       #     #
      #      #
     #       #
    #        #
   #         #
  #          #
 #           #
#            #
 #           #
  #          #
   #         #
    #        #
     #       #
      #      #
       #     #
        #    #
         #   #
          #  #
           # #
            ##
             #