1. 程式人生 > 其它 >繞圈圈(python)

繞圈圈(python)

技術標籤:程式設計提升python演算法

給定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("")