n, m= 19,19
spiral = [[0] * m for _ in range(n)]
c = 'x'
wt=m
hg=n
i=1
j=1
while wt-i>=2:
for k in range(i,wt-1):
spiral[j][k] = c
if hg-j>3:
for l in range(j,hg-1):
spiral[l][wt-2] = c
for k in range(i,wt-2):
spiral[hg-2][k] = c
for l in range(j+2,hg-1):
spiral[l][i] = c
spiral[j+2][i+1] = c
i+=2
j+=2
wt-=2
hg-=2
for i in range(n):
for j in range(m):
print(str(spiral[i][j]).ljust(3), end=' ')
print()
Результат:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 x x x x x x x x x x x x x x x x x 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x 0
0 x x x x x x x x x x x x x x x 0 x 0
0 x 0 0 0 0 0 0 0 0 0 0 0 0 0 x 0 x 0
0 x 0 x x x x x x x x x x x 0 x 0 x 0
0 x 0 x 0 0 0 0 0 0 0 0 0 x 0 x 0 x 0
0 x 0 x 0 x x x x x x x 0 x 0 x 0 x 0
0 x 0 x 0 x 0 0 0 0 0 x 0 x 0 x 0 x 0
0 x 0 x 0 x 0 x x x 0 x 0 x 0 x 0 x 0
0 x 0 x 0 x 0 x 0 0 0 x 0 x 0 x 0 x 0
0 x 0 x 0 x 0 x x x x x 0 x 0 x 0 x 0
0 x 0 x 0 x 0 0 0 0 0 0 0 x 0 x 0 x 0
0 x 0 x 0 x x x x x x x x x 0 x 0 x 0
0 x 0 x 0 0 0 0 0 0 0 0 0 0 0 x 0 x 0
0 x 0 x x x x x x x x x x x x x 0 x 0
0 x 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x 0
0 x x x x x x x x x x x x x x x x x 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0