0
Help me to correct this code Matrix pattern
Print the following pattern for the given number of rows. Pattern for N = 5 1 2 3 4 5 11 12 13 14 15 21 22 23 24 25 16 17 18 19 20 6 7 8 9 10 My code- n = int(input()) upper = int(n/2)+1 lower = n - upper start_i_lower = 0 for i in range(0, upper): if i != 0: i = i + i start = n*i + 1 end = start + n for j in range(start, end): print(j, end =" ") start_i_lower = i print() start_i_lower -= 1 for i in range(0, lower): if(n%2 == 0): start_i_lower -= 1 start = n*(start_i_lower-1) + 1 end = start + n for j in range(1, n+1): print(j+n, end =" ") print()
3 Answers
+ 1
What if it's 6? Please give more examples.
+ 1
Example if test case is:
2
Output
1 2
3 4
for 4
Output
1 2 3 4
9 10 11 12
13 14 15 16
5 6 7 8
And
for 8
Output
1 2 3 4 5 6 7 8
17 18 19 20 21 22 23 24
33 34 35 36 37 38 39 40
49 50 51 52 53 54 55 56
57 58 59 60 61 62 63 64
41 42 43 44 45 46 47 48
25 26 27 28 29 30 31 32
9 10 11 12 13 14 15 16
0
I still don't understand how the return-sequence works; what factor determines it?