i'm very new to programming and the python language, so i'm glad to have found a place I can post my questions. I have been following the "learn python the hard way" tutorial online and have found it very helpful in terms of understanding how to structure code and to do some pretty cool things.

Something that I have decided to do in order to expand what I know is to take ideas and see if I can hash them out in code. Making a tic tac toe game for example. Something that I am currently doing is trying to improve upon a piece of code that computes pi. It works by using the taylor series of arctan where pi = 4(1/1 - 1/3 + 1/5 - 1/7 ...) This converges very slowly and a range of (0, 500000) gives me about 4 correct decimal places.

- Code: Select all
`total = 0`

sign = 1

for n in xrange(0, 500000):

t = sign / (n*2 + 1.0)

total = total + t

sign = sign * -1

print total, t, sign

print total * 4

This is the code i'm using. I had some help from my stepdad in putting it together, but I understand the math behind it and can (almost) make sense of each line as I read it through. The part that is bugging me is this;

- Code: Select all
`print total, t, sign`

If someone could explain the significance of that line, that would really help me out! My goal is to write a similar piece of code based on the arctan of x, where x = tan(pi/8). It should converge much faster.

Lorentz.