Answer to Question #190378 in Python for Arbab Abdul basit

Question #190378

rite a function called diagonal_sum that takes a 2D list(matrix) of 3x3as a parameter andprints its Left diagonal sumand Right diagonal sum


1
Expert's answer
2021-05-07T07:28:24-0400
def diagonal_sum(A):
    n = len(A)
    left = 0
    right = 0
    for i in range(n):
        left += A[i][n-i-1]
        right += A[i][i]
    print(f'Left diagonal sum is {left}')
    print(f'Right diagonal sum is {right}')

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