Write a python program, which asks user to enter value for number of line and then according to input following pattern, should be displayed. - Pratik Ghelani

Pratik Ghelani

Breaking

Sunday, May 10, 2020

Write a python program, which asks user to enter value for number of line and then according to input following pattern, should be displayed.



Program:-

rows = int(input("Enter number of rows:"))
cols = int(input("Enter number of Columns:"))
def swastika(row,col):
            for i in range(row):
                        for j in range(col):
                                    if(i < row // 2):
                                                if (j < col // 2):
                                                            if (j == 0):
                                                                        print("*", end = "")
                                                            else:
                                                                        print(" ", end = " ")
                                               
                                                elif (j == col // 2):
                                                            print(" *", end = "")
                                                else:
                                                            if (i == 0):
                                                                        print(" *", end = "")   
                                    elif (i == row // 2):
                                                print("* ", end = "")
                                    else:
                                                if (j == col // 2 or j == col - 1):
                                                            print("* ", end = "")
                                                elif (i == row - 1):
                                                            if (j <= col // 2 or j == col - 1):
                                                                        print("* ", end = "")
                                                            else:
                                                                        print(" ", end = " ")
                                                else:
                                                            print(" ", end = " ")
                        print()

swastika(rows, cols) 


Output:-





No comments:

Post a Comment