this is what I have done as loop:
def cont_frac(k):
n=1
tempk=k
x=0
D=2.0
if k<1:
print("Invalid Input")
else:
while tempk>1:
n=n+2
tempk=tempk-1
while(k>=1):
N=n*n
x=N/(D+x)
n=n-2
k=k-1
this is what I have done as recursively
n=1
k=int(input("enter the value of k:"))
p=k
def n_inc(tempk):
while tempk>1:
n=n+2
tempk=tempk-1
return n
def conts_frac(k):
x=0
D=2.0
if k<1:
print("invalid Input")
else:
n_inc(p)
N=n*n
x=N/(D+x)
n=n-2
return conts_frac(k-1)
conts_frac(k)
Now question is why this error UnboundLocalError
is occurring in recursion part?
UnboundLocalError: local variable 'n' referenced before assignment