Input a 4*3 table, calculate the sum of each row.
时间: 2024-03-26 09:42:26 浏览: 89
MATLAB code to calculate the 3D skeleton of a binary volume
Sure, here is a Python code that can calculate the sum of each row in a 4*3 table:
```python
table = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12]]
row_sums = []
for row in table:
row_sum = sum(row)
row_sums.append(row_sum)
print(row_sums)
```
Output:
```
[6, 15, 24, 33]
```
In the above code, `table` is a 4*3 table (a list of lists) with 4 rows and 3 columns. We then iterate over each row in the table, calculate the sum of the row using the `sum()` function, and append the row sum to a new list called `row_sums`. Finally, we print out the `row_sums` list, which contains the sum of each row in the table.
阅读全文