请问25的课后作业这个运动代码原理是什么
matrix = [,,
]
rows = len(matrix)
cols = len(matrix)
left = 0
right = cols - 1
top = 0
bottom = rows - 1
result = []
while left <= right and top <= bottom:
for col in range(left, right + 1):
result.append(matrix)
for row in range(top + 1, bottom + 1):
result.append(matrix)
if left < right and top < bottom:
for col in range(right - 1, left, -1):
result.append(matrix)
for row in range(bottom, top, -1):
result.append(matrix)
left = left + 1
right = right - 1
top = top + 1
bottom = bottom - 1
print(result) 本帖最后由 jackz007 于 2022-10-11 13:48 编辑
你应该明白,大家都很忙,没人愿意专门为你去看懂每一行代码,你应该把题目贴出来。
再一个,你首先应该把根据自己的理解令你感到疑惑和不解的地方挑出来,进行针对性提问,大家都很忙,你懂的。
页:
[1]