In this article you learn about how to find log in Python, before starting you need to understand the ‘math’ function in python. Python doesn’t understand ‘log’ function so we need to import log header (reference) file, for importing header file into python we use the ‘import’ keyword in python. How to find log in python.

So the first line of program is:

import math

As we discuss above import is used for inserting the math function in python program, because log function is defined in math, so that’s why it is important to first insert the log header file, make sure this program is written in Python Script Mode, If you don’t know about Python script mode click here.

Now we need to ask the user for to input the number, so we write.

print(“Enter the number of x: “, end=” “)

*print() is a keyword that is used for displaying something on screen, it print the string or value of variable on screen as a output.

*end=” ” is a special keyword that is mean this line is not terminated, on next statement when we enter the value the value input in this line, doesn’t need to start new line.

Now we need to input the value of x, for inputting the value in python we use input keyword.

x=int(input())

Here ‘x’ is variable, when we enter the value the number store on x variable, if you don’t know about variable you can click here.

As you know that int mean integer which is data type, here we need number in integer format so that’s why we use ‘int’.

input() is used for inputting the value from user.

print(“Enter the number of y: “, end=” “)

In this statement we asking to the user that enter the number of y.

y=int(input())

The user need to enter the value of y.

logv=int(math.log(2,2))

In this statement we initialize the log variable, make sure we are finding the log of number on (base 2).

print(“The log of “, x, ” on base 2 is: “, logv)

So this is the final statement of over program, that statement print the result of log.

## Program:

import math

print(“Enter the number of x: “, end=” “)

x=int(input())

print(“Enter the number of y: “, end=” “)

y=int(input())

logv=int(math.log(x,2))

print(“The log of”, x, “on base 2 is:”, logv)

## Output:

Enter the number of x: 2

Enter the number of y: 3

The log of 2 on base 2 is: 1

Hope you find this article helpful if you have any question comment me below, I’ll reply to your comment as soon as possible.