By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,302 Members | 1,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,302 IT Pros & Developers. It's quick & easy.

Beginner question: Logs?

P: n/a
Hey everyone! I'm a math student working on a short script involving
logs. I have a function on my scientific calculator, and was wondering
if there was a similar funtion in python.

For example:

(log65536)/(log4)= 8

I've searched around a bit and haven't been able to find anything.

Thanks!

-Christian

Jul 19 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Svens wrote:
Hey everyone! I'm a math student working on a short script involving
logs. I have a function on my scientific calculator, and was wondering
if there was a similar funtion in python.

For example:

(log65536)/(log4)= 8

I've searched around a bit and haven't been able to find anything.


import math

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Jul 19 '05 #2

P: n/a
Hey thanks...

Still getting an error message though. Here's what i'm doing:
------
import math
log10(15625)
------
-It says that log10 is not defined, but it is since the module is
imported, right?

Jul 19 '05 #3

P: n/a
Svens wrote:
Hey thanks...

Still getting an error message though. Here's what i'm doing:
------
import math
log10(15625)
------
-It says that log10 is not defined, but it is since the module is
imported, right?


No, read the tutorial.

import math
math.log10(15625)

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Jul 19 '05 #4

P: n/a
Svens wrote:
Hey thanks...

Still getting an error message though. Here's what i'm doing:
------
import math
log10(15625)
------
-It says that log10 is not defined, but it is since the module is
imported, right?


try this:

import math
math.log10(15625)
Jul 19 '05 #5

P: n/a

On Jun 1, 2005, at 9:04 PM, Svens wrote:
Hey thanks...

Still getting an error message though. Here's what i'm doing:
------
import math
log10(15625)
------
-It says that log10 is not defined, but it is since the module is
imported, right?


do either

import math
math.log10(15625)
from math import *
log10(15625)

from math import log10
log10(15625)


-- Elliot Temple
http://www.curi.us/
---
[This E-mail scanned for viruses by Declude Virus]

Jul 19 '05 #6

P: n/a
Elliot Temple wrote:
from math import *
log10(15625)


It's always a good idea, especially when answering a beginner's
question, to add the caution that this form ("from xxx import *") has
certain dangers** associated with it, and is widely considered poor
style, and should really only rarely be used. (The math module is
probably one of the few places where some people make an exception,
however, but it's still not a good habit to get into.)

-Peter
Jul 19 '05 #7

P: n/a
> import math
math.log10(15625)


To find out the names of function in the math module without checking the
docs, do
dir(math) #same for any other module
To get more info, do
help(math) # same for any other module with a doc string


Terry J. Reedy

Jul 19 '05 #8

P: n/a

"Peter Hansen" <pe***@engcorp.com> wrote in message
news:Q7********************@powergate.ca...
Elliot Temple wrote:
from math import *
log10(15625)


It's always a good idea, especially when answering a beginner's
question, to add the caution that this form ("from xxx import *") has
certain dangers** associated with it, and is widely considered poor
style, and should really only rarely be used.


Which is why I often do things like
import math as m
m.log...



Jul 19 '05 #9

P: n/a
Peter Hansen wrote:
It's always a good idea, especially when answering a beginner's
question, to add the caution that this form ("from xxx import *") has
certain dangers** associated with it, and is widely considered poor
style, and should really only rarely be used.


Better still, don't even *mention* it to a beginner.
They don't need to know about it. At all. Really.

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
Jul 19 '05 #10

P: n/a
Greg Ewing wrote:
Peter Hansen wrote:
It's always a good idea, especially when answering a beginner's
question, to add the caution that this form ("from xxx import *") has
certain dangers** associated with it, and is widely considered poor
style, and should really only rarely be used.


Better still, don't even *mention* it to a beginner.
They don't need to know about it. At all. Really.


Well, the OP's use is precisely why "from xxx import *" exists: the
interactive prompt.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Jul 19 '05 #11

P: n/a
Robert Kern wrote:
Greg Ewing wrote:

[about the "from xxx import *" syntax]
Better still, don't even *mention* it to a beginner.
They don't need to know about it. At all. Really.


Well, the OP's use is precisely why "from xxx import *" exists: the
interactive prompt.


In that case (and, really, any time) Terry's solution is quite suitable
and an excellent substitute. Even at the interactive prompt some of the
dangers (mostly the potential for name collisions) of "from xxx import
*" are still present.

-Peter
Jul 19 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.