Basic Programs

If Else Programs

While loop Programs

For loop Programs

List Programs


Python Program to Print a Hollow Square Star Pattern using For Loop


This example shows, how to print hollow square pattern using for loop.

Example.py
a = int(input("Enter the Rows: "))
for i in range(1,a+1):
    for j in range(1,a+1):
        if i==1 or i==a or j==1 or j==a:
            print("*", end="")
        else:
            print(" ", end="")
    print()

Output

Enter the Rows: 10

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

Prev Next