def pi(times):
seq = []
counter = 0
for x in range(times):
counter += 2
seq.append(\"((%f**2)/(%f*%f))*\"%(float(counter), float(counter-1),
You appear to have found a bug in eval
where it can't handle insanely long expressions:
>>> eval("1.0*"*10000+"1.0")
1.0
>>> eval("1.0*"*100000+"1.0")
# segfault here
I use the phrase "insanely long" advisedly though. Don't do it that way, calculate the pieces as you go. There is no reason to be using eval
in this situation.
Why use eval()
at all?
def pi(times):
val = 1
counter = 0
for x in range(times) :
counter += 2
val *= float(counter)**2/(counter**2 - 1)
return val * 2
Does the exact same thing.