Python Program to Print (Generate) Diamond Star Pattern

This python program prints 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 Diamond pattern. Given row value of 5, total numbers of line in pattern will be 9.

Python Source Code: Diamond Pattern


# Diamond pattern

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

# Upper part of 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):
        print("*", end="")
    print()

# Lower part of 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):
        print("*", end="")
    print()

Output

Enter number of row: 8

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