sli1que at yahoo.com
Sun Apr 25 22:22:46 CEST 2010
From: bob gailer <bgailer at gmail.com>
To: tutor at python.org
Sent: Sun, April 25, 2010 12:52:10 PM
Subject: Re: [Tutor] sqrt?
On 4/24/2010 11:00 PM, Kirk Z Bailey wrote:
> ok gang, My desktop runs 2.5, and for my college algebra I needed to do som quadratic equation work. This involves squareroots. So I fired uop the interactive idle and imported math. I then tried to play with sqrt.
As Hugo pointed out - asking good questions is important. That includes being really specific. "play" and "nothing" are not specific. We can guess - we might even be right - but that is costly for all of us in time.
Python rarely gives "nothing".
You usually get some result (perhaps you don't agree with it) or some error (traceback). Sometimes there is no visible result, as the case with import.
So if I were willing to spend some time guessing I'd guess that you did and got something like:
>>> import math
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'sqrt' is not defined
Please either confirm or alter the above. IOW show us what you entered and what you got.
Did you read the Python Manual's explanation of import?
> Importing math does not import a sqrt function.
Not under that name, as a global variable. It did create a global name math. Math has attributes, one of which is sqrt.
> Now riddle me this: if string.foo makes it do a function FOO on a string
Wow - so many assumptions, errors and generalities. Where would I even begin?
> , whyfore and howcome does math.sqrt not do square roots on a simple number like 4???
O but it does, as others have pointed out
> I am now officiciously pissed.
I am a newbie but after typing "import math"
you can do a dir(math) to get the available first level methods available to you.
>>> import math
['__doc__', '__file__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'hypot', 'isinf', 'isnan', 'ldexp', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor