Diagonal difference of a 2D matrix

How should I fix my code so that it passes all critical cases, not just some in HackerRank?

#! / bin / python3

import maths
bone import
randomly import
import re
import system

# Complete the diagonalDifference function below.
def diagonalDifference (arr):
sum_diag1 = 0
sum_diag2 = 0
arr_2d = []
    print (arr)

for i in the beach (len (arr)):
for j in range (len (arr)):
if i == j:
sum_diag1 + = arr[i][j]
            
            
            
            elif i + j == (len (arr)) - 1:
sum_diag2 + = arr[i][j]
                
                
                
                print (arr[i][j])


returns abs (sum_diag1 - sum_diag2)

if __name__ == __ hand __:
fptr = open (os.environ['OUTPUT_PATH'], & # 39; w & # 39;)

n = int (input ())

arr = []

    for _ in the range (n):
arr.append (list (map (int, input (). rstrip (). split ())))

result = diagonalDifference (arr)

fptr.write (str (result) + & # 39;  n & # 39;)

fptr.close ()