+ 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??

5th Nov 2016, 2:32 PM
Navaneetha Babu
Navaneetha Babu - avatar
2 ответов
+ 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)
5th Nov 2016, 2:52 PM
Demeth
Demeth - avatar
0
tnxx
5th Nov 2016, 3:34 PM
Navaneetha Babu
Navaneetha Babu - avatar