LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-01-2004, 01:38 AM   #1
draetsch
LQ Newbie
 
Registered: May 2004
Distribution: searching
Posts: 5

Rep: Reputation: 0
python newbie


Hi,
I wanted to try some things with python and installed them on my system.
The tutorial went well, but as I wanted to do some math things I get failures.

For example I want to use pi (dump example, but anyway):



Code:
import math
2 * pi
I get the following failure message:

Code:
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in -toplevel-
    2 * pi
NameError: name 'pi' is not defined
Can someone enlighten me with the basic use of modules?
 
Old 09-01-2004, 03:55 AM   #2
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
Check the constant's name is correct. Usually it'd be something like math.PI or whatever.
 
Old 09-01-2004, 04:28 AM   #3
draetsch
LQ Newbie
 
Registered: May 2004
Distribution: searching
Posts: 5

Original Poster
Rep: Reputation: 0
yeah,
math.pi did it. Thanks alot

Another problem with the same background. When I want to use a function of math i.e. acos() and I use it the old way:

Code:
acos(45)
I get the old failuremessage, ok

but when I try:

Code:
math.acos(45)
I get


Code:
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in -toplevel-
    math.acos(45)
ValueError: math domain error
What did I do wrong?
 
Old 09-01-2004, 04:31 AM   #4
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
What's your complete code? Eg.
Code:
import math
result = math.acos(45)
print result
 
Old 09-01-2004, 05:08 AM   #5
gizmo_thunder
Member
 
Registered: Apr 2004
Posts: 101

Rep: Reputation: 15
acos == arccos ( i.e. cos inverse )
since cos doesnt' take any values above 1 and below -1 its
giving that error.. may be you want to use cos function
to find out the cos value for a given angle.
and the angle has to be in radians most probably.
hope this helps
 
Old 09-01-2004, 05:10 AM   #6
draetsch
LQ Newbie
 
Registered: May 2004
Distribution: searching
Posts: 5

Original Poster
Rep: Reputation: 0
I have no code yet, I am only learning at the moment but your code is what I had in mind. But I get a failure:

Code:
>>> import math
>>> result = math.acos(45)

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in -toplevel-
    result = math.acos(45)
ValueError: math domain error
>>> print result

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in -toplevel-
    print result
NameError: name 'result' is not defined
 
Old 09-01-2004, 05:16 AM   #7
draetsch
LQ Newbie
 
Registered: May 2004
Distribution: searching
Posts: 5

Original Poster
Rep: Reputation: 0
Oh somebody was faster than I,
yeah, okay I was mathematically wrong.
math.acos(0.5) i.e. works.

Thanks to you all. You helped me very much to get a foot in python.
 
Old 09-01-2004, 09:41 AM   #8
onnyloh
Member
 
Registered: Nov 2002
Posts: 57

Rep: Reputation: 15
actually u can check a module member by using python prompt.

step is as follow
python #open a prompt
import math # import math module
dir(math) # list math member
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie, getting simple python script to work Monjawi Programming 6 10-03-2005 11:51 AM
python call function in same file(very newbie question) rmanocha Programming 2 11-21-2004 12:04 AM
newbie python question: doing more than one thing in a for loop SerfurJ Programming 1 03-18-2004 10:14 AM
python linux newbie mdw Slackware 4 05-13-2003 04:38 PM
Newbie learning Python busbarn Programming 3 08-09-2002 10:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration