This Python program uses loops to draw the uppercase letter 'G' 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 more complex text-based shapes.
def draw_letter_g(rows):
cols = rows
for i in range(rows):
for j in range(cols):
if i == 0 or i == rows - 1:
print("*", end="")
elif j == 0:
print("*", end="")
elif i == rows // 2 and j >= cols // 2:
print("*", end="")
elif j == cols - 1 and i >= rows // 2:
print("*", end="")
else:
print(" ", end="")
print()
# Run the program
rows = int(input("Enter number of rows: "))
draw_letter_g(rows)
*******
*
*
* ****
* *
* *
*******
- The outer loop iterates over rows, and the inner loop over columns
- The first and last rows are filled with asterisks
- The first column always contains an asterisk
- In the middle row, the second half is filled to form the horizontal bar of 'G'
- In the lower half, the last column contains asterisks to complete the curve