+ 1
I need to find sum of series 1/2+1/4+1/8+.. n= int(raw_input("enter the limit") s=0 i=2 while(i<=n): x=float(1\i) s=s+x i=i+2 print s is this the correct program??
2 Answers
+ 10
that's how it should look like in Python 3 without mistakes:
n = int(input("enter the limit: "))
s = 0
i = 2
while i <= n:
x = 1 / i
s += x
i += 2
print (s)
you can look for the difference and mistakes in your code. also it could be written much shorter and simpler, like:
n = int(input("limit: "))
s = sum(1/x for x in range(2, n+1, 2))
print (s)
0
tnxx