Answer to Question #230536 in Python for kaavya

Question #230536

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




1
Expert's answer
2021-08-30T01:35:35-0400
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS