Write a python program to print star in a Rectangular pattern

Write a python program to print star in a Rectangular pattern 

Explanation:- 

To print the rectangle take input of no of rows and columns from the user and  store the values in the variables r and c respectively.

Initialize 2 for loops to iterate over rows and columns respectively.

To print rectangle we have to put up a if condition to star if and if it is a 1st row or column or last row or column else print space.  

Code:- 

r=int(input("Rows "))

c=int(input("Columns "))

for i in range(r):

    for j in range(c):

        if(i==0 or i==(r-1) or

        j==0 or j==(c-1)):

            print("*",end=" ")

        else:

            print(" ",end=" ")

    print()

Run the code


Post a Comment

0 Comments