Python example to print Mirrored Half Diamond Star Pattern

diamondrows = 9
# Loop from 0 to the number of rows using For Loop.
for m in range(0, diamondrows):
    # Loop from 0 to the number of rows -iterator value of the parent
    # For loop using another For loop(Nested For loop).
    for n in range(0, diamondrows - m):
        # Print the space character in the inner For loop.
        print(' ', end='')
    # Loop from 0 to the iterator value of the parent For loop
    # using another For loop(Nested For loop).
    for l in range(0, m):
        # Print the star character
        print('*', end='')
    # After the end of the inner for Loops print the Newline Character.
    print()
# Loop from number of rows to 0 in decreasing order using For loop.
for m in range(diamondrows, 0, -1):
    # Loop from 0 to the number of rows -iterator value of the parent
    # For loop using another For loop(Nested For loop).
    for n in range(0, diamondrows - m):
        # Print the space character in the inner For loop.
        print(' ', end='')
    # Loop from 0 to the iterator value of the parent For loop
    # using another For loop(Nested For loop).
    for l in range(0, m):
        # Print the star character
        print('*', end='')
    # After the end of the inner for Loops print the Newline Character.
    print()

OUTPUT:

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

Leave a Comment