# Program to sum 1//2^n correct to 0.0001 accuracy # N is the number of loop iterations N = 50 # n is the loop variable n = 0 sum = 0.0 while n <= N : psum = sum sum = sum + (1.0/2.0)**n n = n + 1 if sum-psum < 0.0001 : print(n, ' ' ,sum) break if n == N : print("Required accuracy not reached in ", N, "iterations.")