Answer to Question #222927 in Python for srikanth

Question #222927
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-05T14:23:31-0400
x = int(input())
N = int(input())
S = 0
k = 1
for i in range(N):
	S += k*(x**(2*i+1))
	k *= -1
print(S)

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