Python Forum
natural logarithm print
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
natural logarithm print
#1

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?
Reply
#2
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
>>>
Reply
#3
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)) ??
Reply
#4
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'?
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#5
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.
Reply
#6
o.k.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Natural language processing project maaaa2401 1 1,778 Dec-04-2020, 07:26 PM
Last Post: Larz60+
  a generator that computes squares of first 20 natural numbers mdshamim06 1 8,895 Oct-01-2019, 10:38 AM
Last Post: buran
  need help in natural language processing irsyadfm 7 4,455 Aug-07-2019, 07:42 AM
Last Post: tkorol
  Natural Logarithm in Python yg89 8 26,654 May-07-2017, 12:36 AM
Last Post: yg89

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020