Python Forum
natural logarithm print - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: natural logarithm print (/thread-5762.html)



natural logarithm print - atux_null - Oct-20-2017


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?


RE: natural logarithm print - Mekire - Oct-20-2017

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
>>>



RE: natural logarithm print - atux_null - Oct-20-2017

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)) ??


RE: natural logarithm print - sparkz_alot - Oct-20-2017

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'?


RE: natural logarithm print - atux_null - Oct-20-2017

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.


RE: natural logarithm print - sparkz_alot - Oct-20-2017

o.k.