Q:

Write a Python program to read a matrix from console and print the sum for each column. Accept matrix rows, columns and elements for each column separated with a space(for every row) as input from the user

0

Write a Python program to read a matrix from console and print the sum for each column. Accept matrix rows, columns and elements for each column separated with a space(for every row) as input from the user

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

rows = int(input("Input rows: "))
columns = int(input("Input columns: "))
matrix = [[0]*columns for row in range(rows)]
print('Input number of elements in a row (1, 2, 3): ')
for row in range(rows):
    lines = list(map(int, input().split()))
    for column in range(columns):
        matrix[row][column] = lines[column]

sum = [0]*columns
print("sum for each column:")
for column in range(columns):
    for row in range(rows):
        sum[column] += matrix[row][column]
    print((sum[column]), ' ', end = '')

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now