Answer to Question #228560 in Python for venkat

Question #228560

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.


1
Expert's answer
2021-08-23T01:19:57-0400


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))

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