pow() works but sqrt() not!?

tonisk metsakuri at gmail.com
Thu Jan 4 09:34:53 CET 2007


you forgot to import math module

>>> import math
>>> math.sqrt(9)
3.0

if you want math functions to your current namespace use:
>>> from math import *

--
Tõnis

On Jan 4, 10:13 am, "siggi" <smusnmrNOS... at yahoo.com> wrote:
> Hi all,
>
> this is a newbie question on :
> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on
> win32
> PC with WinXP
>
> Inhttp://www.python.org/doc/2.3.5/lib/module-math.html
> I read:
>
> "sqrt( x) Return the square root of x."
>
> Now the test for module math with function pow():
> --------------------------------------------------->>> pow(9,9)387420489
>
>  Fine, but sqrt() fails:
> ------------------->>> sqrt(9)I get this error message
>
> 'Traceback (most recent call last):
>   File "<pyshell#3>", line 1, in <module>
>     sqrt(9)
> NameError: name 'sqrt' is not defined'
>
> Same for sin() and cos(). ">>> Import math" does not help. Will I have to
> define the sqrt() function first? If so, how?
> 
> Please help!
> 
> Thank you,
> 
> Siggi




More information about the Python-list mailing list