[Edu-sig] digits of pi

Tim Peters tim.peters at gmail.com
Fri Jul 28 03:27:48 CEST 2006


[Michel Paul]
> When a student first sees Long integer capabilities a question often is "How many
> digits of pi can it show?"  There's a slight disappointment when they find out that
> though there's a Long integer, there is no Long decimal.

The newish `decimal` module has user-settable precision, although it's
more educational to use integers.  See the pi() function at:

    http://docs.python.org/dev/lib/decimal-recipes.html

> I would like to be able to show them a good way to compute a list of an arbitrary
> number of digits in the decimal expansion of of pi.  I think they might find that
> interesting.

See the very old Demo/scripts/pi.py in a Python distribution -- it's
one of the first things Guido coded in Python.  Although I'm
considered a numerical expert, I still have no idea how it works :-)

An enormous number of ways you /could/ proceed:

    http://mathworld.wolfram.com/PiFormulas.html


More information about the Edu-sig mailing list