s = int(input())
list1 = [[0 for i in range(s)] for i in range(s)]
x = 0
y = 0
i = 1
n = s
num = 1
while i:
if n > 0:
for j in range(n):
list1[x][y] = num
num += 1
x += 1
x = x - 1
y = y + 1
else:
i = 0
if n > 1:
for j in range(n - 1):
list1[x][y] = num
num += 1
y += 1
y = y - 1
x = x - 1
else:
i = 0
if n > 1:
for j in range(n - 1):
list1[x][y] = num
num += 1
x -= 1
x = x + 1
y = y - 1
else:
i = 0
if n > 2:
for j in range(n - 2):
list1[x][y] = num
num += 1
y -= 1
y = y + 1
x = x + 1
else:
i = 0
n = n - 2
for i in range(s):
for j in range(s):
print('%3d' % (list1[i][j]),end="")
print('\n', end="")
Python小程序3:转圈圈
最新推荐文章于 2022-07-17 16:27:40 发布