Ответсообщение недоступно
n = int(input('The number: '))
array = [[0] * n for i in range(n)]
i = 1
x = 0
y = -1
go_row = 0
go_column = 1
length = len(str(n ** 2))
while i <= n ** 2:
if 0 <= x + go_row < n and 0 <= y + go_column < n and array[x + go_row][y + go_column] == 0:
x += go_row
y += go_column
array[x][y] = i
i += 1
else:
if go_column == 1:
go_column = 0
go_row = 1
elif go_row == 1:
go_row = 0
go_column = -1
elif go_column == -1:
go_column = 0
go_row = -1
elif go_row == -1:
go_row = 0
go_column = 1
for row in array:
for element in row:
print(str(element).rjust(length), end=' ')
print()