write a program to find the sum S of the series where S = x - x^3 + x^5 + ..... upto N items.
x = int(input('x = '))
n = int(input('n = '))
s = 0
power = 1
sign = 1
for i in range(n):
s += sign * (x**power)
power += 2
sign *= -1
print(f"sum = {s}")
Comments
Leave a comment