Appreciate you looking at this. As title suggests, I am trying to get the nth application of a function.
The first implementation works, however, the second implementation does not. Could someone point me to the reason why? I am using Python 3.4 if that makes a difference.
First implementation:
def repeated(f,n):
def value(x):
k=n
while k>=1:
x=f(x)
k=k-1
return x
return value
Second implementation:
def repeated1(f,n):
def value(x):
while n>=1:
x=f(x)
n=n-1
return x
return value
Error is local variable n is referenced before assignment…This seems off to me as n is defined in the parent function. Appreciate the help.