I am trying to make a program to find the determinant of an N*N matrix and here is my code:
from copy import deepcopy
n = input()
myMatrix = []
for i in range(n):
myMatrix.append(raw_input().split())
def findMinor(matrix, i):
minor = deepcopy(matrix)
del minor[0]
for b in range(len(matrix)-1):
del minor[b][i]
return minor
def det(matrix):
determinant = 0
if len(matrix) == 1:
determinant = matrix[0][0]
else:
for x in range(len(matrix)):
coFactor = det(findMinor(matrix,x))
determinant += int(matrix[0][x]) * (-1)**(2+x) * coFactor
return determinant
print det(myMatrix)
I am getting No-Type error and I'm pretty sure its because I'm calling a function within itself since it is a recursive approach.
Is there any way to fix this? Possibly even dump the second function?