Answer to Question #190344 in Python for python

Question #190344

Write a function called diagonal_sum that takes a 2D list(matrix) of 3x3as a parameter and prints its Left diagonal sum and Right diagonal sum


1
Expert's answer
2021-05-10T08:04:29-0400
def diagonals(A):
    right = A[0][0] + A[1][1] + A[2][2]
    left = A[0][2] + A[2][2] + A[2][0]
    print(f'Right diagonal: {right}')
    print(f'Left diagonal: {left}')

def main():
    A = [[1, 2, 3],
         [1, 1, 1],
         [3, 2, 1]]
    diagonals(A)

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