Python Program to Print Hollow Diamond Star Pattern

Write a Python Program to Print Hollow Diamond Star Pattern using for loop. This Python example uses nested for loops and if-else to return the hollow diamond pattern.

# Python Program to Print Hollow Diamond Star Pattern
 
rows = int(input("Enter Hollow Diamond Pattern Rows = "))

print("Hollow 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, 2 * i):
        if k == 1 or k == i * 2 - 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, 2 * i):
        if k == 1 or k == i * 2 - 1:
            print('*', end = '')
        else:
            print(' ', end = '')
    print()
Python Program to Print Hollow Diamond Star Pattern 1

In this Python Program, we created a hollowDiamondStar function to Print the Hollow Diamond Pattern. The given symbol will replace the star in a hollow diamond pattern.

# Python Program to Print Hollow Diamond Star Pattern

def hollowDiamondStar(rows, ch):
    for i in range(1, rows + 1):
        for j in range(1, rows - i + 1):
            print(end = ' ')
        for k in range(1, 2 * i):
            if k == 1 or k == i * 2 - 1:
                print('%c' %ch, 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, 2 * i):
            if k == 1 or k == i * 2 - 1:
                print('%c' %ch, end = '')
            else:
                print(' ', end = '')
        print()

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

ch = input("Symbol to use in Hollow Diamond Pattern = ")

print("Hollow Diamond Star Pattern")
hollowDiamondStar(rows, ch)
Enter Hollow Diamond Pattern Rows = 12
Symbol to use in Hollow Diamond Pattern = $
Hollow Diamond Star Pattern
           $
          $ $
         $   $
        $     $
       $       $
      $         $
     $           $
    $             $
   $               $
  $                 $
 $                   $
$                     $
 $                   $
  $                 $
   $               $
    $             $
     $           $
      $         $
       $       $
        $     $
         $   $
          $ $
           $
>>>