Answer to Question #327954 in Python for hari

Question #327954

given a matrix of M rows & N columns, you need to find the smallest number in each row & print the sum of the smallest numbers from all rows.

explanation: M=3. given matrix is

1 2 3

4 5 6

7 8 9

the minimum elements of each row 1, 4, 7 => sum is 1+4+7=12

I/p: 3 3

1 2 3

4 5 6

7 8 9

O/p: 12

I/p: 2 3

0 12 -13

-10 0 10

O/p: -23


1
Expert's answer
2022-04-12T16:15:20-0400
def readMat():
    line = input()
    m, n = [int(s) for s in line.split()]


    A = []
    for i in range(m):
        line = input()
        row = [int(s) for s in line.split()]
        A.append(row)
    return A


def calc(A):
    s = 0
    for row in A:
        s += min(row)
    return s


def main():
    A = readMat()
    s = calc(A)
    print(s)


if __name__ == '__main__':
    main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS