Python Program to Print Hollow Half Diamond Star Pattern

Write a Python Program to Print Hollow Half Diamond Star Pattern using for loop. The if statement checks whether i equal j or j equals zero or one and if it is a true print star; otherwise, print space.

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

print("Hollow Half Diamond Star Pattern") 

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

for i in range(rows - 1, 0, -1):
    for j in range(1, i + 1):
        if i == j or j == 1:
            print('*', end = '')
        else:
            print(' ', end = '')  
    print()
Python Program to Print Hollow Half Diamond Star Pattern 1

This Python Program uses a while loop to print Hollow Half Diamond Star Pattern.

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

print("Hollow Half Diamond Star Pattern") 
i = 0
while(i < rows):
    j = 0
    while(j <= i):
        if i == j or j == 0:
            print('*', end = '')
        else:
            print(' ', end = '')
        j = j + 1
    i = i + 1
    print()

i = 1
while(i < rows):
    j = i
    while(j < rows):
        if i == j or j == rows - 1:
            print('*', end = '')
        else:
            print(' ', end = '') 
        j = j + 1
    i = i + 1
    print()
Enter Hollow Half Diamond Pattern Rows = 8
Hollow Half Diamond Star Pattern
*
**
* *
*  *
*   *
*    *
*     *
*      *
*     *
*    *
*   *
*  *
* *
**
*
>>>

In this Python example, we created a hollowHalfDiamond function to Print the Hollow Half Diamond Pattern. It replaces the star in hollow half diamond with the given symbol.

# Python Program to Print Hollow Half Diamond Star Pattern

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

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

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

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

print("Hollow Half Diamond Star Pattern")

hollowHalfDiamond(rows, ch)
Enter Hollow Half Diamond Pattern Rows = 10
Symbol to use in Hollow Half Diamond Pattern = $
Hollow Half Diamond Star Pattern
$
$$
$ $
$  $
$   $
$    $
$     $
$      $
$       $
$        $
$       $
$      $
$     $
$    $
$   $
$  $
$ $
$$
$
>>>