Python Program to Print Hollow Square Pattern

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

Python Source Code: Hollow Square Pattern


# Hollow square pattern in Python

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

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

Output: Hollow Square Pattern

Enter number of rows: 8
Hollow square pattern is: 

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