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
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()
Comments
Leave a comment