Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Newbie question - Advanced math functions available under Windows?

Reply
Thread Tools

Newbie question - Advanced math functions available under Windows?

 
 
The Toad
Guest
Posts: n/a
 
      07-02-2004

I'm completely new to Python and just installed it on my Win 2000
machine. I was planning to use it for quick-and-dirty numerical
programming. The sort of thing people did in QuickBasic before DOS
was replaced by Windows.

When I try to use numerical functions like sqrt() or sin(), I get
error messages like

>>> x = sqrt(10)

Traceback (most recent call last):
File "<pyshell#0>", line 1, in -toplevel-
x = sqrt(10)
NameError: name 'sqrt' is not defined
>>>


The math module documentation says that these math functions are "thin
wrapers" around the platform C library funtions. This seems to assume
a Unix/Linux system platform.

Does this mean that math functions like sqrt(), etc. are not available
in Python when running on Windows based systems? Thanks in advance.

DB


 
Reply With Quote
 
 
 
 
Brian Jones
Guest
Posts: n/a
 
      07-02-2004
If you are working from the python shell, you will want to import the
math module first:

>>> import math


then call the functions like so:

>>> math.sqrt(10)

3.1622776601683795

Hope that helps,

-- Brian Jones

On Fri, 02 Jul 2004 18:31:58 -0400, The Toad <(E-Mail Removed)> wrote:
>
>
> I'm completely new to Python and just installed it on my Win 2000
> machine. I was planning to use it for quick-and-dirty numerical
> programming. The sort of thing people did in QuickBasic before DOS
> was replaced by Windows.
>
> When I try to use numerical functions like sqrt() or sin(), I get
> error messages like
>
> >>> x = sqrt(10)

> Traceback (most recent call last):
> File "<pyshell#0>", line 1, in -toplevel-
> x = sqrt(10)
> NameError: name 'sqrt' is not defined
> >>>

>
> The math module documentation says that these math functions are "thin
> wrapers" around the platform C library funtions. This seems to assume
> a Unix/Linux system platform.
>
> Does this mean that math functions like sqrt(), etc. are not available
> in Python when running on Windows based systems? Thanks in advance.
>
> DB
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


 
Reply With Quote
 
 
 
 
Tim Heaney
Guest
Posts: n/a
 
      07-02-2004
The Toad <(E-Mail Removed)> writes:
>
> The math module documentation says that these math functions are "thin
> wrapers" around the platform C library funtions. This seems to assume
> a Unix/Linux system platform.
>
> Does this mean that math functions like sqrt(), etc. are not available
> in Python when running on Windows based systems? Thanks in advance.


No, you just need to import the math module.

>>> import math
>>> math.sqrt(10)

3.1622776601683795

If you want, you can import sqrt into your namespace

>>> from math import sqrt
>>> sqrt(10)

3.1622776601683795

Often, you see people import everything from a module into their
namespace with an asterisk

>>> from math import *
>>> sqrt(10)

3.1622776601683795

I hope this helps,

Tim
 
Reply With Quote
 
The Toad
Guest
Posts: n/a
 
      07-02-2004
On Fri, 02 Jul 2004 18:59:13 -0400, Tim Heaney
<(E-Mail Removed)> wrote:

>The Toad <(E-Mail Removed)> writes:
>>
>> The math module documentation says that these math functions are "thin
>> wrapers" around the platform C library funtions. This seems to assume
>> a Unix/Linux system platform.
>>
>> Does this mean that math functions like sqrt(), etc. are not available
>> in Python when running on Windows based systems? Thanks in advance.

>
>No, you just need to import the math module.
>
> >>> import math
> >>> math.sqrt(10)

> 3.1622776601683795
>
>If you want, you can import sqrt into your namespace
>
> >>> from math import sqrt
> >>> sqrt(10)

> 3.1622776601683795
>
>Often, you see people import everything from a module into their
>namespace with an asterisk
>
> >>> from math import *
> >>> sqrt(10)

> 3.1622776601683795
>
>I hope this helps,
>
>Tim



Thanks to Tim and Brian! This helps a great deal.

DB
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
Re: Advanced Python Programming Oxford Lectures [was: Re: *Advanced*Python book?] Michele Simionato Python 1 03-27-2010 06:10 AM
math.h trig functions questions (and some forgotten high school math) Mark Healey C Programming 7 05-22-2006 10:42 AM
Why can I not use: Math a=new Math(); chirs Java 18 03-02-2004 06:00 PM
basic math functions - strange result (newbie in xslt) Nicolas Stern XML 2 08-13-2003 04:12 PM



Advertisments