log2() function in python by R4R Team

-log2() is a python function which is predefined in math library and use for find the value of log of base 2.

Syntax-

math.log2(num)

Example-

number is 16
log2(16) will give 4.0

number is 64
log2(64) will give 6.0

number is 1024
log2(1024) will give 10.0


program-

import math
print("Enter any number")
a=int(input())
print("Log2 of number is "+str(math.log2(a)))

print("Enter another number")
a=int(input())
print("Log2 of number is "+str(math.log2(a)))


output-

Enter any number
16
Log2 of number is 4.0
Enter another number
1024
Log2 of number is 10.0

Enter any number
34
Log2 of number is 5.087462841250339
Enter another number
546
Log2 of number is 9.092757140919852


-In this program, firstly we import the 'math' library by using import math then take a input of integer value and print the log10 value.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!