~2 min read • Updated Oct 11, 2025
Program Overview
This Python program uses nested loops to draw the uppercase letter 'C' using the '*' character.
The number of rows is taken as input and determines the height of the letter.
This exercise helps practice loop structures and conditional logic for rendering text-based shapes.
Python Code:
def draw_letter_c(rows):
cols = rows # Width of the letter C equals its height in this example
for i in range(rows):
for j in range(cols):
if i == 0 or i == rows - 1:
print("*", end="")
elif j == 0:
print("*", end="")
else:
print(" ", end="")
print()
# Run the program
rows = int(input("Enter number of rows: "))
draw_letter_c(rows)
Sample Output (input: 6):
******
*
*
*
*
******
Step-by-Step Explanation:
- The outer loop iterates over rows, and the inner loop over columns
- The first and last rows are filled entirely with asterisks
- In other rows, only the first column contains an asterisk, creating a hollow shape
- This structure visually resembles the letter 'C'
Written & researched by Dr. Shahin Siami