Part of the series

Several example codes

~1 min read • Updated Oct 8, 2025

Program Overview

This Python program reads the number of rows from the user and prints a pattern using asterisks (*) that resembles the letter "P" rotated 90 degrees counterclockwise.
The pattern consists of a left-aligned triangle followed by a horizontal line at the bottom.


Python Code:


def draw_rotated_p(rows):
    # Upper triangle part
    for i in range(1, rows):
        print("*" * i)

    # Bottom horizontal line
    print("*" * rows)

# Run the program
rows = int(input("Enter number of rows: "))
draw_rotated_p(rows)

Sample Output (rows = 5):


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

Step-by-Step Explanation:

- The first loop prints a left-aligned triangle with increasing number of asterisks
- The final line prints a full horizontal row of asterisks equal to the number of rows
- This creates a shape similar to the letter "P" rotated counterclockwise


Written & researched by Dr. Shahin Siami