def pi(times):
seq = []
counter = 0
for x in range(times):
counter += 2
seq.append("((%f**2)/(%f*%f))*"%(float(counter), float(counter-1), float(counter+1)))
seq.append("1.0")
seq = "".join(seq)
seq = eval(seq)
return seq*2
Anywhere past 85000 terms I get a segmentation fault and python quits. How can I avoid this? Why is it crashing? Can't it just please use more memory or something?
Why use
eval()
at all?Does the exact same thing.
You appear to have found a bug in
eval
where it can't handle insanely long expressions: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.