We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6d189f8 commit 00302e5Copy full SHA for 00302e5
5. Fifth_Semester/PYTHON/Minor Assignment 4/Q12.py
@@ -0,0 +1,21 @@
1
+'''
2
+Ques 12: Define a function that returns the sum of all the elements in a specified column in a matrix. Write a
3
+Python program that reads a 3-by-4 matrix and displays the sum of each column. Here is a sample
4
+run:
5
+Enter a 3-by-4 matrix row by row:
6
+1.5 2 3 4
7
+5.5 6 7 8
8
+9.5 1 3 1
9
10
+
11
+def column_sum(matrix, col_index):
12
+ return sum(row[col_index] for row in matrix)
13
14
+matrix = []
15
+print("Enter a 3-by-4 matrix row by row:")
16
+for _ in range(3):
17
+ row = list(map(float, input().split()))
18
+ matrix.append(row)
19
20
+for col in range(4):
21
+ print(f"Sum of column {col + 1}: {column_sum(matrix, col)}")
0 commit comments