控制台输入一个大于1的整数n,然后产生一个二维列表,尺寸是n*n。每一个列表元素的值从1到n*n,依次排列。假设输入为3,输出如下:
[1,2,3]
[4,5,6]
[7,8,9]
[1,4,7]
[2,5,8]
[3,6,9]
a = int(input("please enter an integer greater than 1:"))
c = e = a
d = f = 1
b = []
if a < 1:
a = int(input("The input value should greater than 1,please re-enter:"))
else:
while e > 0:
while c - (d - 1) * a > 0:
b.insert(0,c)
c -= 1
print(b)
d += 1
e -= 1
c = d*a
b = []
e = c = a
d = 1
while e > 0:
while c - (d - 1) * a > 0:
g = f+((c - (d - 1) * a) - 1)*3
b.insert(0,g)
c -= 1
print(b)
f += 1
d += 1
e -= 1
c = d * a
b = []