trig functions from the standard library

This is the place for queries that don't fit in any of the other categories.

trig functions from the standard library

Postby lorentz » Sun Jun 09, 2013 3:38 pm

Hello,

quick question - when looking things up in the python standard library I keep hitting the same problem which leaves me convinced i'm doing something wrong. I need to incorporate arctan(x) into my program where x = (sqrt(2) - 1) Evidently I still need to look up the square root function aswell, but just when I have been trying to do things like the arctan(45) I keep getting errors.

Code: Select all
math.atan(45)
Is what the standard library gives as the way of returning the arctan of 45, but both in 'calculator' mode and running a program I get errors.

I imagine i'm doing something trivially silly, but i'm still learning :)
lorentz
 
Posts: 9
Joined: Mon May 27, 2013 4:46 pm

Re: trig functions from the standard library

Postby stranac » Sun Jun 09, 2013 3:57 pm

lorentz wrote:but both in 'calculator' mode and running a program I get errors.

What errors do you get?

Also, by calculator mode, I assume you mean the interactive interpreter?
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1093
Joined: Thu Feb 07, 2013 3:42 pm

Re: trig functions from the standard library

Postby lorentz » Sun Jun 09, 2013 4:03 pm

Ah yes, interactive mode is what I meant.

The error that I get is;

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'math' is not defined.
lorentz
 
Posts: 9
Joined: Mon May 27, 2013 4:46 pm

Re: trig functions from the standard library

Postby metulburr » Sun Jun 09, 2013 4:14 pm

You have to import the module before using it's attributes
Code: Select all
import math
print(math.atan(45))
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1318
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: trig functions from the standard library

Postby lorentz » Sun Jun 09, 2013 5:51 pm

Thanks!
lorentz
 
Posts: 9
Joined: Mon May 27, 2013 4:46 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests