Instagram
youtube
Facebook
Twitter

Left Half Diamond Pattern in Python

 A  Left Half Diamond Pattern in Python

     
     Short Description:
     This Python program prints a left-aligned half diamond using asterisks (*).
     It first prints an increasing triangle with spaces to the left, then a decreasing triangle, forming a diamond           shape aligned to the left.

     Explanation (in dot points):

  • rows = int(input(...))
    • Takes the number of rows as input from the user.

     
  • for i in range(1, rows + 1)
    • Creates the upper half of the diamond.
    • Spaces decrease while stars increase.

     
  • for i in range(rows - 1, 0, -1)
    • Creates the lower half of the diamond.
    • Spaces increase while stars decrease.

     
  • " " * (rows - i)
    • Adds spaces before stars to align the pattern to the left.

     
  • "*" * i
    • Prints i stars in each row.

Program:

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)