Maximum, Minimum and sum of Matrix
Write a program to print the maximum, minimum and sum of all elements in the matrix.
Input
The first line of input will contain two space-separated integers, denoting the M and N.
The next M following lines will contain N space-separated integers, denoting the elements of each list.
Output
The first line of output should be the maximum of all elements in the matrix.
The second line of output should be the minimum of all elements in the matrix.
The third line of output should be the sum of all elements in the matrix.
Explanation
For example, if the given M is 3 and N is 3, read the inputs in the next three lines. If the numbers given in the next three lines are the following.
1 2 3
10 20 30
5 10 15
The first line of output should print the maximum of all the elements in the matrix, which is 30.
The second line of output should print the minimum of all the elements in the matrix, which is 1
The third line of output should print the sum of all the elements in the matrix, which is 96.
So the output should be
30
1
96
Sample Input 1
3 3
1 2 3
10 20 30
5 10 15
Sample Output 1
30
1
96
Code:
def convert_string_to_int(list_a):
new_list = []
for item in list_a:
num = int(item)
new_list.append(num)
return new_list
m, n = input().split()
m, n = int(m), int(n)
num_list = []
for i in range(m):
list_a = input().split()
list_a = convert_string_to_int(list_a)
num_list.append(list_a)
row_max = []
row_min = []
row_sum = []
for row in num_list:
row_max.append(max(row))
row_min.append(min(row))
row_sum.append(sum(row))
print(max(row_max))
print(min(row_min))
print(sum(row_sum))
Input
2 5
-50 20 3 25 -20
88 17 38 72 -10
Output
88
-50
183