Calculate Natural Logarithm

Write a Python program that uses the math module to calculate the natural logarithm of a user input number. The function natural_log(n) should return the natural logarithm of n.

Example 1:

Input: natural_log(20)
Output: 2.995732273553991

Example 2:

Input: natural_log(7)
Output: 1.9459101490553132

Use the math.log() function from the math module.

import math

def natural_log(n):
    return math.log(n)

# Test the function

© Let’s Data Science


Unlock AI & Data Science treasures. Log in!