Week 5- matrix multiplication exercise

Hi,

I have created a recursive function for 2*2 matrix multiplication as part of assignment but i am facing some issue while returning the final output. Can some one please help me please.

Function created:
A = [[1,1],[1,0]]

def square_matrix_power(a,n):

if n==1:

``````return a
``````

else:

``````B = [[(A[0][0]*a[0][0]+A[0][1]*a[1][0]),(A[0][0]*a[0][1]+A[0][1]*a[1][1])],[(A[1][0]*a[0][0]+A[1][1]*a[1][0]),(A[1][0]*a[0][1]+A[1][1]*a[1][1])]]

print(B)

square_matrix_power(B,n-1)
``````

test run results for

1. print(square_matrix_power(A,1))
[[1, 1], [1, 0]] ------ Working as expected
2. print(square_matrix_power(A,3))
[[2, 1], [1, 1]] ----- properly multiplied in 1st loop for A^2
[[3, 2], [2, 1]] ------ Properly multiplied in 2nd loop for A^3
None ------- Returned value, not worked as expected

I din’t know why value None returning finally even after properly multiplied in loops…

The last statement of the function should be:
`return square_matrix_power(B,n-1)`