In this Python program, we will learn how to print the hollow square pattern.
Here is the source code of the program to print the hollow square pattern.
# Python Program to Print the Hollow Square Star Pattern
# Using For Loop
# Take the Input From the User
side = int(input("Enter any Side of a Square: "))
# Print the Output
print("Hollow Square Star Pattern")
for i in range(side):
for j in range(side):
if(i == 0 or i == side - 1 or j == 0 or j == side - 1):
print('*', end = ' ')
else:
print(' ', end = ' ')
print()
Enter any Side of a Square: 5
Hollow Square Star Pattern
* * * * *
* *
* *
* *
* * * * *
# Python Program to Print the Hollow Square Star Pattern
# Using While Loop
# Take the Input From the User
side = int(input("Enter any Side of a Square: "))
# Print the Output
print("Hollow Square Star Pattern")
i = 0
while(i < side):
j = 0
while(j < side):
if(i == 0 or i == side - 1 or j == 0 or j == side - 1):
print('*', end = ' ')
else:
print(' ', end = ' ')
j = j + 1
i = i + 1
print()
Enter any Side of a Square: 6
Hollow Square Star Pattern
* * * * * *
* *
* *
* *
* *
* * * * * *
Comments