130. Python Program to Compute the Given Series -1+2-4+8-16+--------+1024
How does this program work?
- This program is used to find the Sum of the given series -1+2-4+8-16+--------+1024 using Python.
- The integer entered by the user is stored in variable x and n .
- By using the for loop condition we can easily calculate the sum of given series.
Here is the code
n = int(input("Enter a number: "))
s = 0
j = 1
for i in range(1,n+1):
if(i%2==0):
s=s+j
else:
s=s-j
print(j, end=" ")
j=j+j
i+=1
print("\nSum: ",s)