I wanted to write a recursive function to fit curves. For some reasons my results didn't looked good so I boiled down the problem to one easy example:
Number = 6
Successor = 0
def Fuction(Number, Successor):
if (Number - Successor)+1>0:
Successor += 1
Fuction(Number, Successor)
else:
return(Fuction(Number, Successor))
A = Fuction(Number, Successor)
print(f'The Successor of {Number} is {A}')
When I do this the Kernel dies. How can I fix it? (I followed the awnser : Why does my recursive function return none)
Fuction()again in theif (Number - Successor) + 1 > 0branch? When do you expect this function to stop recurring, and what is it supposed to return in that branch?elsebranch. "Base case" means "stop the recursion", yet you doreturn(Fuction(Number, Successor))in this branch, continuing the recursion infinitely. You can justreturn Successor, then your problem reduces to the link you provided because the recursive branch isn't returning anything. As an aside, only classes should start with uppercase letters. The convention is to use lower-case for vars.