This Python program reads the number of rows from the user and prints a hollow rectangle pattern using asterisks (*).
The rectangle has a solid border and a hollow center. The number of rows determines the height of the rectangle, and the width is fixed or can be adjusted.
def draw_hollow_rectangle(rows, cols):
for i in range(rows):
for j in range(cols):
if i == 0 or i == rows - 1 or j == 0 or j == cols - 1:
print("*", end="")
else:
print(" ", end="")
print()
# Run the program
rows = int(input("Enter number of rows: "))
cols = rows # You can change this to any fixed width if needed
draw_hollow_rectangle(rows, cols)
*****
* *
* *
* *
*****
- The outer loop runs for each row
- The inner loop runs for each column
- Asterisks are printed at the borders: first/last row or first/last column
- Spaces are printed inside the rectangle to create the hollow effect