Newbie question - Advanced math functions available under Windows?

T

The Toad

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
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
 
B

Brian Jones

If you are working from the python shell, you will want to import the
math module first:

then call the functions like so:
3.1622776601683795

Hope that helps,

-- Brian Jones
 
T

Tim Heaney

The Toad said:
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.
3.1622776601683795

If you want, you can import sqrt into your namespace
3.1622776601683795

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

I hope this helps,

Tim
 
T

The Toad

No, you just need to import the math module.

3.1622776601683795

If you want, you can import sqrt into your namespace

3.1622776601683795

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

3.1622776601683795

I hope this helps,

Tim


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

DB
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,662
Latest member
sxarexu

Latest Threads

Top