Input a 4*3 table, calculate the sum of each row.
Inut:
12 integers in 4*3 tabel
Output:
4 integers with each one in single line
Input sample:
12 4 6
8 23 3
15 7 9
2 5 17
output sample:
22
34
31
24
Input a 4*3 table, calculate the sum of each row.
Inut:
12 integers in 4*3 tabel
Output:
4 integers with each one in single line
Input sample:
12 4 6
8 23 3
15 7 9
2 5 17
output sample:
22
34
31
24
参考GPT和自己的思路:
好的,针对这个问题,你可以使用以下的 Python 代码实现计算每一行的和:
table = []
for i in range(4):
row = input().split() # 读取输入的一行,以空格分隔的整数字符串
row = [int(x) for x in row] # 把字符串列表转换成整数列表
table.append(row) # 把该行添加到表格中
row_sums = []
for row in table:
row_sum = sum(row) # 计算该行的和
row_sums.append(row_sum) # 添加该行的和到列表中
for sum in row_sums:
print(sum) # 输出每一行的和
你可以把这段代码复制到 Python 环境中运行,然后输入示例中给定的数值,即可得到该表格每一行的和。希望我的回答能够帮到你!