Python Program to Print Hollow Rectangular Pattern

This python program generates or prints hollow rectangular pattern made up of stars up to n lines.

Python Source Code: Hollow Rectangular Pattern


# Hollow rectangular pattern in Python

# Reading number of rows and columns
row = int(input("Enter number of rows: "))
col = int(input("Enter number of columns: "))

print("Hollow rectangular pattern is: ")
for i in range(1,row+1):
    for j in range(1,col+1):
        if i==1 or i==row or j==1 or j==col:
            print("*", end="")
        else:
            print(" ", end="")
    print()

Output: Hollow Rectangular Pattern

Enter number of rows: 4
Enter number of columns: 12
Hollow rectangular pattern is: 

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