In this Python program, we will learn how to print the hollow box star(*) pattern.
Here is the source code of the program to print the hollow box star(*) pattern.
# Python Program to Print the Hollow Box Star Pattern
# Using For Loop
# Take the Input from the User
rows = int(input("Enter the total Number of Rows: "))
columns = int(input("Enter the total Number of Columns: "))
# Print the Output
print("Hollow Box Star Pattern") 
 
for i in range(1, rows + 1):
    for j in range(1, columns + 1):
        if(i == 1 or i == rows or j == 1 or j == columns):          
            print('*', end = '  ')
        else:
            print(' ', end = '  ')
    print()
Enter the total Number of Rows: 5
Enter the total Number of Columns: 5
Hollow Box Star Pattern
* * * * *
* *
* *
* *
* * * * *
# Python Program to Print the Hollow Box Star Pattern
# Using While Loop
# Take the Input From the User
rows = int(input("Enter the total Number of Rows: "))
columns = int(input("Enter the total Number of Columns: "))
# Print the Output
print("Hollow Box Star Pattern")
i = 1 
while(i <= rows):
    j = 1;
    while(j <= columns ):
        if(i == 1 or i == rows or j == 1 or j == columns):          
            print('*', end = '  ')
        else:
            print(' ', end = '  ')
        j = j + 1
    i = i + 1
    print()
Enter the total Number of Rows: 6
Enter the total Number of Columns: 6
Hollow Box Star Pattern
* * * * * *
* *
* *
* *
* *
* * * * * *
Comments