#生成n*n的矩阵
import random
n=int(input(‘输入n,产生n*n的方阵:’ ))
a=[[random.randint(1,9) for i in range(n)] for j in range(n)]
for i in a:
print(i)
print( )
x,y=[],[]
xy=input("请输入左上角+右下角坐标:") #输入左上角坐标+右下角坐标,用逗号分隔数字。如:"2,1,14,13"
xy=xy+","
c,j=0,0
for i in range(len(xy)):
if xy[i]==",":
if :
x.append(int(xy[j:i]))
else:
y.append(int(xy[j:i]))
c=c+1
for i in range(y[0],y[1]+1,1):
for j in range(x[0],(x[0]+x[1])//2+1,1):
a[i][j],a[i][]=a[i][],a[i][j]
for i in range(len(a)):
print(a[i])