Answer to Question #292907 in Python for gayi3

Question #292907

write a program to find the sum S of the series where S = x-x^3+x^5+..... upto N terms.


1
Expert's answer
2022-02-01T12:26:05-0500
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