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

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -