Skip to content

Commit d36bc81

Browse files
authored
Create zigzag.py
1 parent 4b21c7c commit d36bc81

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Python/zigzag.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import numpy as np
2+
3+
rows = int(input("Enter number of rows "))
4+
cols = int(input("Enter number of columns "))
5+
arr = np.zeros([7,16],dtype = int)
6+
num = 0
7+
flag = 0
8+
i = 0
9+
j = 0
10+
11+
while j <= cols-1:
12+
if i<=rows-1 and flag == 0:
13+
num = num + 1
14+
arr[i][j] = num
15+
if i == rows - 1 :
16+
i = i - 1
17+
j = j + 1
18+
flag = 1
19+
else:
20+
i = i + 1
21+
j = j + 1
22+
23+
elif (i<rows-1 and i>=0) and flag == 1:
24+
num = num + 1
25+
arr[i][j] = num
26+
if i == 0:
27+
i = i + 1
28+
j = j + 1
29+
flag = 0
30+
else:
31+
i = i - 1
32+
j = j + 1
33+
34+
for i in range(rows):
35+
for j in range(cols):
36+
if(arr[i][j] == 0):
37+
print(" ",end =" ")
38+
else:
39+
print(arr[i][j],end =" ")
40+
print()

0 commit comments

Comments
 (0)