Создать матрицу размером N×M (вводится пользователем) и заполнить ее по спирали по часовой стрелке. Начало — левый верхний угол.
m, n = int(input()), int(input()) matrix = [[0 for x in range(n)] for y in range(m)] counter = 1 start_column = 0 end_column = n - 1 start_row = 0 end_row = m - 1 while start_column <= end_column and start_row <= end_row: for i in range(start_column, end_column + 1): matrix[start_row][i] = counter counter += 1 start_row += 1 for i in range(start_row, end_row + 1): matrix[i][end_column] = counter counter += 1 end_column -= 1 for i in range(end_column, start_column - 1, -1): matrix[end_row][i] = counter counter += 1 end_row -= 1 for i in range(end_row, start_row - 1, -1): matrix[i][start_column] = counter counter += 1 start_column += 1 for i in range(m): for j in range(n): print((str(matrix[i][j])).ljust(3), end = " ") print()