recursion - Python recursive zeno() function -
in python, need define recursive function takes number returns sum 1/2^0 + 1/2^1 + 1/2^2 + 1/2^3 + ... + 1/2^n. need accomplish without using or while loop. have tried.
def zeno(n): if n==0: return 1/1 else: return float(1/1 + 1/2**zeno(n-1))
def zeno(n): if n==0: return 1 #return 1 base n==0 case, x ^ 0 1 else: return 0.5**n + zeno(n-1) #calculate (1/2) ^ n + (1/2)^(n-1) recursively
Comments
Post a Comment