Write a program that prompts the user for the number of values for which it will calculate the base 2 log of each value. Use a for loop to iterate the set of values and print the log for each. Here is the formula to change the base of a log:
loga b = log10 b / log10 a
Sample output appears below.
This program will calculate the Base 2 log of a set of
numbers<LINERETURN>
===============================================================<LINERETURN>
Enter the upper limit to calculate base 2
logarithms:<SPC>5<ENTER>
Input<TAB>|<SPC>Log2<LINERETURN>
1<TAB>|<SPC>0.0000<LINERETURN>
2<TAB>|<SPC>1.0000<LINERETURN>
3<TAB>|<SPC>1.5850<LINERETURN>
4<TAB>|<SPC>2.0000<LINERETURN>
5<TAB>|<SPC>2.3219<LINERETURN>
HERE IS THE REQUIRED SOLUTION IN PYTHON
here is the code
#import log2 function from math library
from math import log2
#take input for upperlimit
num=int(input("Enter the upperlimit to calculate the base 2
logarithm: "))
#display result
print("input Log2")
for i in range(1,num+1):
print(i," ",log2(i))
Get Answers For Free
Most questions answered within 1 hours.