From d36bc8167f196d9c01fb603fd1104129fd5b08bd Mon Sep 17 00:00:00 2001 From: Raghav Babbar <89309326+BabbarRaghav@users.noreply.github.com> Date: Sat, 1 Oct 2022 19:51:03 +0530 Subject: [PATCH] Create zigzag.py --- Python/zigzag.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Python/zigzag.py diff --git a/Python/zigzag.py b/Python/zigzag.py new file mode 100644 index 00000000..1b656780 --- /dev/null +++ b/Python/zigzag.py @@ -0,0 +1,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=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()