Sum of the series
Write a program to find the sum
The first line of input is an integer
If we take
X value as 2 in the series upto 5 terms.Then the series is 2 - 23 + 25 - 27 + 29
So, the output should be
410.
Sample Input 1
2
5
Sample Output 1
410
#Python 3.9.5
def getSum(x, membership):
i = 1
sumSeries = 0
for member in range(membership):
if member % 2 > 0:
sumSeries += -x**i
i += 2
else:
sumSeries += x**i
i += 2
return sumSeries
x = int(input())
membership = int(input())
print(getSum(x, membership))
Comments
Leave a comment