Python Code Example: left arrow pattern

In this code, the user is prompted to enter the number of rows for the left arrow pattern. The first for loop is responsible for printing the top half of the pattern, and the second for loop prints the bottom half. The print(" " * (num_rows - i), end="") statement is used to print spaces before each row to align the asterisks properly. The print("*" * i) statement prints the desired number of asterisks (*) for each row.

# Get the number of rows from the user
num_rows = int(input("Enter the number of rows: "))

# Display the left arrow pattern
for i in range(1, num_rows + 1):
    print(" " * (num_rows - i), end="")
    print("*" * i)

for i in range(num_rows - 1, 0, -1):
    print(" " * (num_rows - i), end="")
    print("*" * i)
Output
    *
   **
  ***
 ****
*****
 ****
  ***
   **
    *