繞圈圈(python)
阿新 • • 發佈:2021-02-06
給定4,輸出下列形式的資料:
程式碼:
SIZE = 4
array = [[0] * SIZE]
for i in range(SIZE - 1):
array += [[0] * SIZE]
orient = 0
j = 0
k = 0
for i in range(1, SIZE*SIZE+1):
array[j][k] = i
if j + k == SIZE - 1:
if j > k:
orient = 1
else:
orient = 2
elif (k == j) and (k >= SIZE/2):
orient = 3
elif (j == k-1) and (k <= SIZE/2):
orient = 0
if orient == 0:
j += 1
elif orient == 1:
k += 1
elif orient == 2:
k -= 1
elif orient == 3:
j -= 1
for i in range(SIZE):
for j in range (SIZE):
print('%02d ' % array[i][j], end="")
print("")