├── coding (pattern (G)) └── README.md /coding (pattern (G)): -------------------------------------------------------------------------------- 1 | def Pattern(line): 2 | pat="" 3 | for i in range(0,line): 4 | for j in range(0,line): 5 | if ((j == 1 and i != 0 and i != line-1) or ((i == 0 or 6 | i == line-1) and j > 1 and j < line-2) or (i == ((line-1)/2) 7 | and j > line-5 and j < line-1) or (j == line-2 and 8 | i != 0 and i != line-1 and i >=((line-1)/2))): 9 | pat=pat+"*" 10 | else: 11 | pat=pat+" " 12 | pat=pat+"\n" 13 | return pat 14 | line = 7 15 | print(Pattern(line)) 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This code used to print the pattern G. 2 | If we try to analyze this picture with a (row, column) matrix and the circles represent the position of stars in the pattern G, we will learn the steps. Here we are performing the operations column-wise. 3 | So for the first line of stars, we set the first if condition, where the row position with 0 and (n-1) won’t get the stars and all other rows from 1 to (n-1), will get the stars. 4 | Similarly, for the second, third and fourth column we want stars at the position row = 0 and row = (n-1). 5 | The other steps are self-explanatory and can be understood from the position of rows and columns in the diagram. 6 | --------------------------------------------------------------------------------