Newbie question - Advanced math functions available under Windows?

Discussion in 'Python' started by The Toad, Jul 2, 2004.

  1. The Toad

    The Toad Guest

    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
     
    The Toad, Jul 2, 2004
    #1
    1. Advertising

  2. The Toad

    Brian Jones Guest

    Re: Newbie question - Advanced math functions available underWindows?

    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 <> 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
    >
     
    Brian Jones, Jul 2, 2004
    #2
    1. Advertising

  3. The Toad

    Tim Heaney Guest

    Re: Newbie question - Advanced math functions available underWindows?

    The Toad <> 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
     
    Tim Heaney, Jul 2, 2004
    #3
  4. The Toad

    The Toad Guest

    On Fri, 02 Jul 2004 18:59:13 -0400, Tim Heaney
    <> wrote:

    >The Toad <> 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
     
    The Toad, Jul 3, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chirs
    Replies:
    18
    Views:
    776
    Chris Uppal
    Mar 2, 2004
  2. AciD_X
    Replies:
    4
    Views:
    8,113
    Jonathan Turkanis
    Apr 1, 2004
  3. Mark Healey
    Replies:
    7
    Views:
    1,490
    Tim Prince
    May 22, 2006
  4. Michele Simionato
    Replies:
    1
    Views:
    605
    Lacrima
    Mar 27, 2010
  5. VK
    Replies:
    15
    Views:
    1,180
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page