forked from NiharRanjan53/HacktoberFest_2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zigzag.py
40 lines (36 loc) · 828 Bytes
/
zigzag.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
import numpy as np
rows = int(input("Enter number of rows "))
cols = int(input("Enter number of columns "))
arr = np.zeros([7,16],dtype = int)
num = 0
flag = 0
i = 0
j = 0
while j <= cols-1:
if i<=rows-1 and flag == 0:
num = num + 1
arr[i][j] = num
if i == rows - 1 :
i = i - 1
j = j + 1
flag = 1
else:
i = i + 1
j = j + 1
elif (i<rows-1 and i>=0) and flag == 1:
num = num + 1
arr[i][j] = num
if i == 0:
i = i + 1
j = j + 1
flag = 0
else:
i = i - 1
j = j + 1
for i in range(rows):
for j in range(cols):
if(arr[i][j] == 0):
print(" ",end =" ")
else:
print(arr[i][j],end =" ")
print()