Instagram
youtube
Facebook
Twitter

Full Diamond Pattern in Python

   Full Diamond Pattern in Python

     
    Short Description:
    This Python program prints a full diamond pattern using asterisks (*).
    It consists of an upper triangle and a lower inverted triangle, both center-aligned, forming a complete                diamond shape.
    Explanation (in dot points):

  • rows = int(input(...))
    • Takes the number of rows (height of half the diamond) from the user.

     
  • for i in range(1, rows + 1)
    • Builds the upper half of the diamond.
    • As i increases, spaces decrease and stars increase.

     
  • for i in range(rows - 1, 0, -1)
    • Builds the lower half of the diamond.
    • As i decreases, spaces increase and stars decrease.

     
  • " " * (rows - i)
    • Adds spaces to center-align each row.

     
  • "* " * i
    • Prints i stars with a space for even spacing.

Progeam:

rows = int(input("Enter the number of rows: "))

for i in range(1, rows + 1):

    print(" " * (rows - i) + "* " * i)

for i in range(rows - 1, 0, -1):

    print(" " * (rows - i) + "* " * i)