-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathPattern-G.py
44 lines (35 loc) · 1.09 KB
/
Pattern-G.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
__author__ = 'Avinash'
# Python3 program to print alphabet pattern G
# * * * * * *
# *
# *
# * * * * * *
# * *
# * *
# * *
# * * * * * *
def print_pattern(n):
# Outer for loop for number of rows
for rows in range(n):
# Inner for loop columns
for columns in range(n):
# prints first row
if ((rows == 0 and (columns != 0 and columns != n-1)) or
# prints last row
(rows == n - 1 and (columns != 0 and columns != n-1)) or
# prints first column
((columns == 0 and (rows != 0 and rows != n-1)) or
# prints last column
(columns == n-1 and rows != n-1 and rows >= (n/2)-1)) or
# prints middle column
(rows == (n/2)-1 and ((n/2)-1 <= columns < n-1))
):
print("*", end=" ")
else:
print(" ", end=" ")
print()
size = int(input("Enter size: \t"))
if size < 8:
print("Enter a size greater than 8")
else:
print_pattern(size)