-1

how do I use python to find the natural log of a user's input?

import math

def log_e(power_of_e):
    math.log = power_of_e
    exponent = math.log
    return exponent

my_number = float(input('Enter a number and I will give you it\'s natural logarithm:'))
print (log_e(my_number))
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Your function never actually calls `math.log()`. Instead it simply returns the value you passed in, clobbering the `math.log()` function in the process. You should look at some basic tutorials on how to call functions. – kindall Mar 03 '18 at 00:33
  • 1
    I removed your tag as `[logging]` does not mean using logarithm at all. the `[e]` means also something different if you hover mouse over the tag it will show hint where is described what the tag stands for .... – Spektre Mar 03 '18 at 08:09

2 Answers2

0
import math

def log_e(power_of_e):
    exponent=math.log(power_of_e)
    return exponent

my_number=float(input('Enter a number and I will give you it\'s natural logarithm:'))
print (format(log_e(my_number),'.3f'))
kindall
  • 178,883
  • 35
  • 278
  • 309
0

math.log takes an optional second argument which is the base to use. math.e is the constant e. Put them together and you get:

import math

def log_e(number):
    return math.log(number, math.e)
kindall
  • 178,883
  • 35
  • 278
  • 309