Answer to Question #322680 in Python for swami

Question #322680

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.



Sample Input 1


2


5


Sample Output 1


410



to solve this approch


if i value is even:


result = summation of the term value and then added to the result



else :


result = Subtraction of the term value and then added to the result

1
Expert's answer
2022-04-02T15:46:54-0400
x = int(input())
n = int(input())
sign = 1
buff = 0
pow = 1
for i in range(n):
	buff += sign*x**pow
	sign *= -1
	pow += 2
print(buff)

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