Answer to Question #218779 in Python for binnu

Question #218779

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





1
Expert's answer
2021-07-19T17:03:07-0400
#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))

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