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
I have to print this pattern for n
= any integer can anyone please help me with it. Thank you in advance
So this was my attempt:
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(start, end):
print(j, end =" ");
start_i_lower -= 1
print()
Aucun commentaire:
Enregistrer un commentaire