I am trying to find the sum for series : 1 − 1 / 2 + 1 / 3 − 1 / 4 + · · · + 1 / 99 − 1 / 100 ** 2
with python.
My code is -
psum = 0
nsum = 0
for k in range(1,100):
if k%2 == 0:
nsum += 1.0/k
else:
psum += 1.0/k
print psum - nsum - 1.0/100**2
The output is 0.69807217931
I don't have the answer and just want to verify if I am doing it right.
This is not a homework question but just random Python practice.