Skip to content

Instantly share code, notes, and snippets.

@fcschmidt
Created November 24, 2018 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcschmidt/95fae557705bfe86f60f8718f2375f15 to your computer and use it in GitHub Desktop.
Save fcschmidt/95fae557705bfe86f60f8718f2375f15 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
def diagonal_principal(m):
ac = 0
m1 = []
while ac <= len(m) - 1:
vet = m[ac]
m1.append(vet[ac])
ac += 1
return sum(m1)
def diagonal_secundaria(m):
dec = len(m) - 1
aux = 0
m2 = []
while dec >= 0:
vet = m[aux]
m2.append(vet[dec])
dec -= 1
aux += 1
return sum(m2)
if __name__ == '__main__':
d = int(input())
m = []
for r in range(0, d):
matrix = list(map(int, input().split()))
m.append(matrix)
d_prin = diagonal_principal(m)
d_sec = diagonal_secundaria(m)
print(d_prin - d_sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment