[python-win32] Re: on the way to find pi!

Gabriel Genellina gagenellina at softlab.com.ar
Tue Jan 25 03:18:12 CET 2005


At 24/1/2005 08:00, you wrote:

># Call pi(20) for first 20 digits, or pi() for all digits
>def pi(n=-1):
>     printed_decimal = False
>     r = f((1,0,1,1))
>     while n != 0:
>         if len(r) == 5:
>             stdout.write(str(r[4]))


>This code gives the number in an unusual format like "3.1415'None'" it has 
>a number part and a string part . I want to seperate these from easc other 
>but I couldn't manage. I mean when I try to turn it into string format 
>then try to use things like [:4] or like that they don't work.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 :)

I bet: you call the function using:
print pi(20)
instead of just:
pi(20)

That function already prints the output, one digit at a time. You could 
accumulate the answer into a list, or perhaps into a string, and get 
thousands of digits; but it doesnt make sense to store the answer in a 
"real normal number" because you are limited by the underlying floating 
point precision to a few decimals. To get pi as a real number, just say: 
from math import pi




More information about the Python-win32 mailing list