Reputation:
I've defined a function which is
from math import *
def func(x):
return log(e,x)
Error is short and clear, do you know why python cannot evaluate
func(1)
,which is equal to ln(1), ?
edit: Since I'm new there, I have posted a silly question, I'm sorry, but now I handled it
Upvotes: 1
Views: 2393
Reputation: 4521
This is the definition of the log
function. As mentioned in the comments, your base cannot be 1
.
def log(x, base=None): # real signature unknown; restored from __doc__
"""
log(x[, base])
Return the logarithm of x to the given base.
If the base not specified, returns the natural logarithm (base e) of x.
"""
pass
You can see the below operations:-
>>> import math
>>>
>>> def func(x):
...
... return math.log(10, x)
...
>>> print func(1)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "<input>", line 3, in func
ZeroDivisionError: float division by zero
>>> print func(2)
3.32192809489
>>> print func(3)
2.09590327429
>>> print func(4)
1.66096404744
>>>
Upvotes: 2
Reputation:
@mike_z was right about what he recommended,
I had a piece of backward arguments, in other words I thinked of the function
math.log(a,b)
or log(a,b)
(depending on how you impoted math modulo)
as if a indicates base ,and b indicates the other operand whose logarithm is to be evaluated
but the true approach is that inverse of sentence above is right,
Tank you all!
Upvotes: 2