I am tyring to multiply the values in an array recursively but I get an error after running the following code :
def multAll(k,A) :
multAllRec(k,A,0)
def multAllRec(k,A,i) :
if i<len(A):
A[i] *= k
multAllRec(k, A, i + 1)
multAll(10,[5,12,31,7,25])
Error : RecursionError: maximum recursion depth exceeded while calling a Python object
multAllRecis guaranteed to call itself again so you will always hit the limit. Looks like you want something along the lines ofif i >= len(A): returnia default value.multAllRecwithout return, that is what is causing the error.def multAll(k,A): return multAllRec(k,A,0) def multAllRec(k,A,i): if i >= len(A): return AmultAllRec()unconditionally calls itself. This needs to be be done conditionally in order for it to stop doing so.