xdm,这题怎么写啊,研究了半天
这题研究了半天 输入的数据是什么类型? 本帖最后由 wp231957 于 2022-5-18 16:04 编辑n=int(input("请输入矩阵阶数:"))
k=[]
for x in range(n):
k.append([])
for y in range(n):
k.append([])
m=1
for x in range(n):
for y in range(n):
k= m
m+=1
for x in range(n):
print(k)
a=[]
b=[]
c=0
d=0
for x in range(n):
a.append(sum(k))
print("横向和=",a)
for x in range(n):
b.append(0)
for x in range(n):
for y in range(n):
b+=k
for x in range(n):
c+=k
d+=k
print("纵向和=",b)
print("正向对角线之和=", c)
print("反向对角线之和=", d)
'''
PS D:\wp> & C:/Programs/Python/python.exe d:/wp/wp/wp1.py
请输入矩阵阶数:8
横向和=
纵向和=
正向对角线之和= 260
反向对角线之和= 260
PS D:\wp>
'''
因输入矩阵过于麻烦,所以我自己自动生成了矩阵,,所以你需补入用户输入矩阵部分代码
参考代码:
n = int(input())
arr = []
col_sum = * n
row_sum = * n
l_r_sum =
l, r = 0, n - 1
for i in range(n):
row = list(map(int, input().split()))
for j in range(n):
col_sum += row
row_sum += sum(row)
l_r_sum += row
l_r_sum += row
l += 1
r -= 1
print(*row_sum)
print(*col_sum)
print(*l_r_sum, sep="\n") 白two 发表于 2022-5-18 15:38
输入的数据是什么类型?
整型
页:
[1]