Можно еще так:
def spiral(n):
dx,dy = 1,0
x,y = 0,0
myarray = [[None]* n for j in range(n)]
for i in range(1,n**2+1):
myarray[x][y] = i
nx,ny = x+dx, y+dy
if 0<=nx
x,y = nx,ny
else:
dx,dy = -dy,dx
x,y = x+dx, y+dy
return myarray
def printspiral(myarray):
n = range(len(myarray))
for y in n:
for x in n:
print (myarray[x][y],end=' ')
print()
n = int(input())
printspiral(spiral(n))