how to make a series in python alternating between + and -

35

n = int(input("Integer n: "))
result = sum((-1)**(k+1) * k**2 for k in range(1, n + 1))
print(result)

Comments

Submit
0 Comments