Python Program to Print Diamond Star Pattern

Write a Python Program to Print Diamond Star Pattern using for loop.

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

print("Diamond Star Pattern") 
k = 0
for i in range(1, rows + 1):
    for j in range(1, rows - i + 1):
        print(end = ' ')
    while k != 2 * i - 1:
        print('*', end = '')
        k = k + 1
    k = 0
    print()

k = 2
l = 1
for i in range(1, rows):
    for j in range(1, k):
        print(end = ' ')
    k = k + 1
    while l <= (2 * (rows - i) - 1):
        print('*', end = '')
        l = l + 1
    l = 1
    print()
Enter Diamond Pattern Rows = 8
Diamond Star Pattern
       *
      ***
     *****
    *******
   *********
  ***********
 *************
***************
 *************
  ***********
   *********
    *******
     *****
      ***
       *
>>> 

We altered the above Python Program and replaced the while loop with for loop to Print the Diamond Star Pattern.

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

print("Diamond Star Pattern") 
for i in range(1, rows + 1):
    for j in range(1, rows - i + 1):
        print(end = ' ')
    for k in range(0, 2 * i - 1):
        print('*', end = '')
    print()

for i in range(1, rows):
    for j in range(1, i + 1):
        print(end = ' ')
    for l in range(1, (2 * (rows - i) )):
        print('*', end = '')
    print()
Python Program to Print Diamond Star Pattern 2

In this Python Program, we created a diamondPattern function that accepts the rows and symbols to Print Diamond Pattern. The sign will replace the star in a diamond pattern.

# Python Program to Print Diamond Star Pattern

def  diamondPattern(rows, ch):
    for i in range(1, rows + 1):
        for j in range(1, rows - i + 1):
            print(end = ' ')
        for k in range(0, 2 * i - 1):
            print('%c' %ch, end = '')
        print()

    for i in range(1, rows):
        for j in range(1, i + 1):
            print(end = ' ')
        for k in range(1, (2 * (rows - i))):
            print('%c' %ch, end = '')
        print()
    
rows = int(input("Enter Diamond Pattern Rows = "))

ch = input("Symbol to Print in Diamond Pattern = ")

print("Diamond Pattern")
diamondPattern(rows, ch)
Enter Diamond Pattern Rows = 10
Symbol to Print in Diamond Pattern = ^
Diamond Pattern
         ^
        ^^^
       ^^^^^
      ^^^^^^^
     ^^^^^^^^^
    ^^^^^^^^^^^
   ^^^^^^^^^^^^^
  ^^^^^^^^^^^^^^^
 ^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^
 ^^^^^^^^^^^^^^^^^
  ^^^^^^^^^^^^^^^
   ^^^^^^^^^^^^^
    ^^^^^^^^^^^
     ^^^^^^^^^
      ^^^^^^^
       ^^^^^
        ^^^
         ^
>>>