numStr = input("请输入一个大于1的正整数:") n = int(numStr) m = n * n i = 1 numbers = [] values = [] while i <=n: #生成列表 values.apped(i) if i % n ==0: numbers.append(values.copy()) value.clear() i += 1 for number in numbers: print(number) i = 0 j=0 while i <n: #列表元素互换 while j <= i: numbers[i][j],numbers[j][i] = numbers[j][i],numbers[i][j] j +=1 j=0 i += 1 form number in numbers: print(number)
原文地址:https://www.cnblogs.com/ppystudy/p/12109843.html
时间: 2024-10-14 05:42:23