Python Forum

Full Version: natural logarithm print
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

i have an exercise to do which asks the user to give 2 numbers x and y. OK i got that. then it needs to print the exponential value of e x, where e is the base of the natural logarithm.
up to now i have:

x=int(input('Please state the value of X: '))
y=int(input('Please state the value of Y: '))

print(math.log(x[,base]))

apparently it returns an error for invalid syntax of the comma separator prior to the word base.
is the coding correct or am i missing something?
math.log(x[,base]) is how it is written in the help docs to indicate that base is an optional argument.  The default is e, so math.log(x) returns ln(x).

From your description however it sounds like you are expected to return e**x, not ln(x).
>>> import math
>>> math.exp(5)
148.4131591025766
>>> e = math.e
>>> e**5
148.41315910257657
>>>
thanks a lot for the quick reply. so if would like to present it it would be something like print('The answer is:',(e**5)) ??
That is unclear. If 'x' were the only variable and since 'e' is a constant, by your description, yes and there would be no need for the 'log' function.

>>> import math
>>>
>>> x = 5
>>> math.e ** x
148.41315910257657
>>>
However you have a second variable 'y', is that meant to be the 'base' and not 'e'?
y is not needed for this part of the equation. is needed for another question.
y is needed for the log of x on base y. this is my next question.
o.k.