Python Code Example: right arrow pattern

In this code, the user is prompted to enter the number of rows for the right 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 inner for loop within each outer loop prints the asterisks (*) for each row. The end="" argument is used to prevent the print() function from printing a new line after each asterisk.

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

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

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