Python Math libraries - How to?

Cousin Stanley cousinstanley at gmail.com
Mon Apr 28 23:37:22 EDT 2008


>
> Here is the arithmetic program I made that it worked before I added
> the "import math" line.  
>
> #volumen.py
> # A program to compute the volume and surface area of a sphere
> import math
>
> ....
> NameError: global name 'pi' is not defined
> ....

>>> from math import *
>>>
>>> def surface( r ) :
...     return 4 * pi * r ** 2
...
>>> def volume( r ) :
...     return ( 4. / 3. ) * pi * r ** 3
...
>>> for n in range( 1 , 11 ) :
...     s = surface( n )
...     v = volume( n )
...     print '    %2d .... %9.4f .... %9.4f ' % ( n , s , v )
...


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona




More information about the Python-list mailing list