The problem is that when a == 0 and we go into the exit condition and must return it to (sum), the program for some reason continues to work and despite the fact that we seem to have had to get out of recursion and return to ( to the sum) we go to the next iteration k + = s (n, n1, a-1,0, k) and after this iteration produces the following error: unsupported operand type (s) for + =: 'int' and 'NoneType' as far as I understand my function is zero here. Also, if n == 2 (the dimension of the matrix is 2, then I simply return "None", although when I went to debugger, then (sum) had a certain value Tell me why the output m this error, and how to correct (if possible) Thanks
import random n1 = int(input('matrix(1): ')) n=[[random.randint(-20,40) for r in range(n1)] for s in range(n1)]# cоздаем матрицу def s(n,n1,a,b=0,k=0):#передаем в функцию(матрица, размерность матрицы,индексы элементов, суму) k+=n[a][b]#считаем суму последнего элемента if a == 0:#условия выхода из рекусии return k k +=s(n,n1,a-1,0,k)#сама рекурсия print(s(n,n1,(n1-1)))#начальные агрументы функции(матрица,размерность,значение первого индекса