I am currently making a program that includes a recursive function that always returns 1. The function looks like this:
def fn(n):
if n <= 1:
return n
elif n > 1 and n % 2 == 0:
return fn(n/2)
elif n > 1 and n % 2 > 0:
return fn(3*n+1)
As I will be creating other functions, I need to create a function that counts how many times fn() is called recursively within the fn() function (How many calls does 'n' take to reach 1). I am able to do this using a global variable, however I am not sure how to do this using another recursive function. Any help would be appreciated. Thanks.