on the way to find pi!

Fredrik Lundh fredrik at pythonware.com
Sun Jan 23 13:39:52 EST 2005


Ali Polatel wrote:

> I found a code which calculates pi with an interesting algorithm the programme code is below:

> [code snipped]

> This code gives the number in an unusual format like "3.1415'None'" it has
> a number part and a string part.

are you sure?

    $ python pi.py
    How many digits? :5
    3.1415
    $ python pi.py
    How many digits? :10
    3.141592653
    $ python pi.py
    How many digits? :20
    3.1415926535897932384

> Any idea how to seperate this 'None' from the number and make it a real
> normal number on which I can do operations like +1 -1 or like that :)

what's the point of that?  the math module already contains pi with as many
decimals as you can put in a Python float:

    $ python
    >>> pi = 3.1415926535897932384
    >>> pi
    3.1415926535897931
    >>> import math
    >>> math.pi
    3.1415926535897931
    >>> pi = math.pi
    True

</F> 






More information about the Python-list mailing list