Python Program to Print (Generate) Hollow Diamond Star Pattern

This python program prints Hollow Diamond pattern made up of stars up to n lines.

In this python program we first read row from user. Here row indicates number of rows that will be printed in one triangle pattern of Hollow Diamond pattern. Given row value of 5, total numbers of line in hollow diamond pattern will be 9.

Python Source Code: Hollow Diamond Pattern


# Hollow Diamond pattern

# Reading number of row
row = int(input('Enter number of row: '))

# Upper part of hollow diamond
for i in range(1, row+1):
    for j in range(1,row-i+1):
        print(" ", end="")
    for j in range(1, 2*i):
        if j==1 or j==2*i-1:
            print("*", end="")
        else:
            print(" ", end="")
    print()

# Lower part of hollow diamond
for i in range(row-1,0, -1):
    for j in range(1,row-i+1):
        print(" ", end="")
    for j in range(1, 2*i):
        if j==1 or j==2*i-1:
            print("*", end="")
        else:
            print(" ", end="")
    print()

Output

Enter number of row: 8

       *
      * *
     *   *
    *     *
   *       *
  *         *
 *           *
*             *
 *           *
  *         *
   *       *
    *     *
     *   *
      * *
       *