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.
def Sum(X, N):
i = 1
sum_Series = 0
for member in range(N):
if member % 2 > 0:
sum_Series += -X**i
i += 2
else:
sum_Series += X**i
i += 2
return sum_Series
X = int(input("Enter an interger X: "))
N = int(input("Enter an interger N: "))
print(Sum(X, N))
Comments
Leave a comment