Answer to Question #308187 in Python for Rikky

Question #308187

Sum of Non-Diagonals


As the creative content member of your newspaper company, you are given the task to publish a puzzle in your local newspaper. For a given MxM integer matrix, the task is to print the sum of all elements other than the diagonal elements,Both the diagonals are to be excluded.


Input

The first line of input is a positive integer M.

The next M lines of input contain M space-separated integers.


Output

The output is an integer that represents the sum of all the numbers in the matrix as mentioned above.


Sample Input1

3

4 1 3

2 5 6

1 2 3

Sample Output1

11


Sample Input2

5

1 2 2 3 3

4 4 5 6 7

9 8 7 6 5

9 2 3 8 8

-4 -2 -2 4 -7

Sample Output2

63


1
Expert's answer
2022-03-09T01:34:47-0500
M = int(input('Enter integer here: '))
l = 0
k = 0
for i in range(M):
    input1 = input('Enter space seperated numbers')
    for i, j in enumerate(input1.split(' ')):
        if i != k:
            l = l + int(j)
    k = k + 1
print(l)

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