Sum of the series
Write a program to find the sum S of the series where S = x - x^3 + x^5 + ....... upto N terms.
Input
The first line of input is an integer X. The second line of input is an integer N.
Explanation
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
Sample Input 2
3
2
Sample Output 2
-24
X = int(input('Enter integer here: '))
N = int(input('Enter integer here: '))
M = 1 + 2*(N-1)
list1 = []
i = 1
j = 0
k = 0
while i <= M:
list1.append(X**i)
i = i + 2
for s in list1:
if (list1.index(s))%2 == 0:
j = j + s
else:
k = k - s
print(j+k)
Enter integer here: 3
Enter integer here: 2
-24
Enter integer here: 2
Enter integer here: 5
410
Comments
Leave a comment