-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdouble-headed-arrow-pattern.py
More file actions
75 lines (58 loc) · 1.71 KB
/
double-headed-arrow-pattern.py
File metadata and controls
75 lines (58 loc) · 1.71 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Python3 implementation of the approach
# Function to print the requried pattern
def drawPattern(N) :
n = N;
row = 1;
# 'nst' is the number of values
nst = 1;
# 'nsp' is the number of spaces
nsp1 = n - 1;
nsp2 = -1;
val1 = row;
val2 = 1;
while (row <= n) :
# Here spaces are printed
# 'csp' is the count of spaces
csp1 = 1;
while (csp1 <= nsp1) :
print(" ",end= " ");
csp1 = csp1 + 1;
# Now, values are printed
# 'cst' is the count of stars
cst1 = 1;
while (cst1 <= nst) :
print(val1,end = " ");
val1 = val1 - 1;
cst1 = cst1 + 1;
# Again spaces have to be printed
csp2 = 1;
while (csp2 <= nsp2) :
print(" ",end = " ");
csp2 = csp2 + 1;
# Again values have to be printed
if (row != 1 and row != n) :
cst2 = 1;
while (cst2 <= nst) :
print(val2,end = " ");
val2 = val2 + 1;
cst2 = cst2 + 1;
print()
# Move to the next row
if (row <= n // 2) :
nst = nst + 1;
nsp1 = nsp1 - 2;
nsp2 = nsp2 + 2;
val1 = row + 1;
val2 = 1;
else :
nst = nst - 1;
nsp1 = nsp1 + 2;
nsp2 = nsp2 - 2;
val1 = n - row;
val2 = 1;
row = row + 1;
# Driver code
if __name__ == "__main__" :
# Number of rows
N = 7;
drawPattern(N);