【发布时间】:2021-06-04 13:17:59
【问题描述】:
我尝试在 python 中创建二维数组,它接受用户的输入以询问要制作多少个二维数组。我的程序还对数组 2d 中每一行的值求和,并打印每个数组的最大值。
示例:
输入:
2 - for how much array need to create
2 -> for how much size array(rows default = 3)
1 2 3
4 5 6
3
0 0 0
2 3 4
5 6 7
输出:
in array 1 is : 2 (represent row) -> (4+5+6) is greatest than (1+2+3)
in array 2 is : 3 (represent row) -> (5+6+7) is greatest
我的程序堆栈如何求和并打印正确的输出。并且对于 +:. 的一些不受支持的操作数类型也有一些问题。也许有人想帮我修复它。这是我的代码
A = int(input("enter how many matrix create: "))
for i in range(A):
B = int(input("enter size : "))
matrix = []
print("enter number: ")
for j in range(B):
a =[]
for k in range(B):
a.append(input())
matrix.append(a)
rows = len(matrix)
cols = len(matrix[0])
total=0
for r in range(0, rows):
rowtotal=0
for s in range(0, cols):
rowtotal=rowtotal+int(matrix[r][s])
print(rowtotal)
total=total+rowtotal
print(total)
我需要您对此的意见。谢谢。
【问题讨论】: