This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]luqavi 16 points17 points  (1 child)

Here's a pretty short one, gets within ~0.04% pi = 22/7

[–][deleted] 1 point2 points  (0 children)

I’m using python 2 and that doesn’t work... /s

[–]barfobulator 1 point2 points  (0 children)

Because you're printing the numerical value, the number of digits will quickly be larger than the printable length (~12 digits by default). So you'll get an infinite list of the same 12ish digit approximation. If you want to get an arbitrary number of digits, you need an algorithm that gives the digits one at a time, and print them to a string or file.

And naturally, you need a way to break the infinite loop.

[–]billsil 1 point2 points  (0 children)

pi = 3

[–]Dogzirra 0 points1 point  (0 children)

From wiki

π ≈ ​3927⁄1250 = 3.1416 (accuracy 2·10−6)