473,569 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Learning Python : >>> import math doesn't work ?

Have carefully installed Python 2.5.1 under XP in dir E:\python25 .
ran set path = %path% ; E:\python25
Python interactive mode works fine for simple arithmetic .
Then tried >> import math
>> x = sqrt(100)
Get error Name error : name 'sqrt' is not defined
Same thing with sin(x) .
I'm unable to find "math" , "sqrt" , or "sin" anywhere in lib , Libs
or include directories .
The Tutorial does not clear this up .
Please help. Thanks Dave pd******@earthl ink.net
Nov 19 '07 #1
4 22041
On Nov 18, 8:48 pm, pdlem...@earthl ink.net wrote:
Have carefully installed Python 2.5.1 under XP in dir E:\python25 .
ran set path = %path% ; E:\python25
Python interactive mode works fine for simple arithmetic .
Then tried >> import math
>> x = sqrt(100)
Get error Name error : name 'sqrt' is not defined
Same thing with sin(x) .
I'm unable to find "math" , "sqrt" , or "sin" anywhere in lib , Libs
or include directories .
The Tutorial does not clear this up .
Please help. Thanks Dave pdlem...@earthl ink.net
Hi,

I believe that should be:
x = math.sqrt(100)

'import math' makes available the functions in the math module, but
they are still inside the math namespace, so still require 'math.'
If you will be using sqrt a lot, you can create a copy of the function
in the local namespace using
sqrt = math.sqrt
x = sqrt(100)

[In principle, you can give it any name you want, but of course it is
sensible to use a name that makes sense.
E.g. if you were a Spanish speaker, you could say instead
raiz = math.sqrt
x = raiz(100)
]

For more details about how 'import'ing works, check out the Python
tutorial.

Hope that helps.
Best wishes,

David.


Nov 19 '07 #2
On Nov 19, 10:48 am, pdlem...@earthl ink.net wrote:
Have carefully installed Python 2.5.1 under XP in dir E:\python25 .
ran set path = %path% ; E:\python25
Python interactive mode works fine for simple arithmetic .
Then tried >> import math
>> x = sqrt(100)
Get error Name error : name 'sqrt' is not defined
Same thing with sin(x) .
I'm unable to find "math" , "sqrt" , or "sin" anywhere in lib , Libs
or include directories .
The Tutorial does not clear this up .
Please help. Thanks Dave pdlem...@earthl ink.net
use it like: x = math.sqrt (100) and math.sin(x)
Nov 19 '07 #3
On Nov 19, 3:46 pm, windspy <wind...@gmail. comwrote:
use it like: x = math.sqrt (100) and math.sin(x)
alternatively import like this:

from math import sqrt, sin

.... and use it like you have.

Nov 19 '07 #4

"Asun Friere" <af*****@yahoo. co.ukwrote in message
news:86******** *************** ***********@s36 g2000prg.google groups.com...
| On Nov 19, 3:46 pm, windspy <wind...@gmail. comwrote:
| use it like: x = math.sqrt (100) and math.sin(x)
|
| alternatively import like this:
|
| from math import sqrt, sin
|
| ... and use it like you have.

Or,
import math as m # to save typing, especially in interactive mode
x = m.sin(1) #etc

Nov 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4326
by: Thomas Brathans | last post by:
Hi, when I try to execute the obove mentioned to synchronise the servertime by a php-script, it doesn't work. Other shell-commands work fine. Executing ntpdate <server> directly in the shell works also well. So why doesn't it work? Thanks...
4
2119
by: edg | last post by:
This works: $b = $a->method1(); $c = $b->method2(); I'd like to get this all on one expression, something like: $c = ${$a->method1()}->method2(); which doesn't work.
3
84589
by: Paul Thompson | last post by:
When I put a <div ...> inside a <table> specification, functionality is not there. When I put the <table> inside the <div> everything works. Why is that?
2
2490
by: beetle | last post by:
Hello, I'm storing data in several different binary tree's. The root node is located in a struct containing general data about the tree. struct lnode { char *fname; int nentry;
1
3294
by: Alex VanderWoude | last post by:
I am trying to <include> some text into an XML documentation topic, but that text is stored in a file that is in a different directory than the "current" XML file. Using a relative path does not appear to work, because the base being used is the Common7\IDE directory, not my original source directory. Here is the situation: MyApp...
2
1460
by: Maureen | last post by:
Hi: Our ASP.NET webapplication works on our development webserver, but fails on our production webserver - I cannot get any detailed error information: -It is an application -Mode in <customErrors> is set to Off (case is correct) -Cannot get any detailed error messages -Both dev and prod servers appear to be configured identically
1
12767
by: Alex Chun | last post by:
I have an Access database -- a .mdb file -- on a server on our network. When the file is in use -- i.e. there is an associated .ldb file -- I cannot open the database by double-clicking its icon; nothing happens. However, I *am* able to open the file by running Access and choosing File Open. (Also, when the database is not in use,...
6
17349
by: Stef Mientki | last post by:
hello, I want to find all files with the extension "*.txt". From the examples in "Learning Python, Lutz and Asher" and from the website I see examples where you also may specify a wildcard filegroup. But when I try this files = os.listdir('D:\\akto_yk\\yk_controle\\*.txt') I get an error message
1
3475
by: DukeRev | last post by:
I made a box where if you hover over the DIV tag it changes the color of the link text. It works in firefox and opera, but it doesn't work in IE. Doesn't anyone know why it doesn't work and how to fix it? I made a <DIV> clickable by extending the <a> tag div.top_nav a { width: 100%; height: 100%; display: block; }
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.