How to print hollow rectangle / square pattern in python

In this article we are going to see how to :

Write a program to print dynamic hollow rectangle / square pattern in python.

height = int(input("Enter the height of the rectangle: "))
width = int(input("Enter the width of the rectangle: "))
i = 0

while(i < height) :
    j = 0
    whilej < width ):
        if(i == 0 or i == height-1 or j == 0 or j == width-1):
            print("",end="* ")
        else:
            print(end="  ")
        j = j+1
    print("")
    i = i + 1

Output:

Enter the height of the rectangle: 5
Enter the width of the rectangle: 5
*       *       *       *       *       
*                                 *
*                                 *
*                                 *
*       *       *       *       *
Output 2:
Enter the height of the rectangle: 3
Enter the width of the rectangle: 6
*       *       *       *       *       *       
*                                          *
*       *       *       *       *       *

Thanks for reading.

© Copyright - 2018 - 2021 | All rights reserved at Funda of Web IT