rite a function called diagonal_sum that takes a 2D list(matrix) of 3x3as a parameter andprints its Left diagonal sumand Right diagonal sum
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}')
Comments
Leave a comment