Python Program for Hollow Square Star Pattern
Printing Hollow Square Star Pattern
In this Python Program, we will be discussing about how to write a program to print Hollow Square Star Pattern. In this pattern, there are n*n rows and columns are present. We can see in this pattern, all stars are present at the boundary of the pattern. And filled with spaces inside the boundary. “For Loop” and “If-Else” Condition will help to print this Hollow Square Star Pattern.
Step 1. Start
Step 2. Take input from the user and store it in any variable (‘num’ in this case).
Step 3. Run a loop ‘i’ number of times to iterate through all the rows. From i=0 to num.
Step 4. Run a nested loop inside the main loop for printing stars . From j=0 to num.
Step 5. Inside the above loop print stars only if i==0 or i==num-1 or j==0 or j==num-1 in all other cases print a blank space.
Step 6. Move to the next line by printing a new line by using print() function.
Stop 7. Stop
num = int(input("Enter number:")) for i in range(0, num): for j in range(0, num): if i == 0 or j == 0 or j == num-1 or i == num - 1: print("*", end="") else: print(" ", end="") print() # This code is contributed by Shubhanshu Arya (Prepinsta Placement Cell Student)