This Python program uses a loop to draw the uppercase letter 'D' using the '*' character in the terminal.
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.
def draw_letter_d(rows):
cols = rows # Width of the letter D equals its height in this example
for i in range(rows):
for j in range(cols):
if j == 0 or (i == 0 and j < cols - 1) or (i == rows - 1 and j < cols - 1) or (j == cols - 1 and i != 0 and i != rows - 1):
print("*", end="")
else:
print(" ", end="")
print()
# Run the program
rows = int(input("Enter number of rows: "))
draw_letter_d(rows)
*****
* *
* *
* *
* *
*****
- The outer loop iterates over rows, and the inner loop over columns
- The first column always contains an asterisk
- The first and last rows are filled with asterisks except the last column
- The last column contains asterisks only in the middle rows, forming the curve of the letter 'D'