Question

Write a program that prompts the user for the number of values for which it will...

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>

Homework Answers

Answer #1

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))

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(Python Programming) Write a program that prompts a user for a positive integer and then uses...
(Python Programming) Write a program that prompts a user for a positive integer and then uses a loop to calculate and display the sum of specific fractions as follows: Let's say the user enters 5, then your program will compute: 1/5 + 2/4 + 3/3 + 4/2 + 5/1 which is 8.7.
Write a complete program that prompts the user to enter the number of students and each...
Write a complete program that prompts the user to enter the number of students and each student’s score, then finally displays the highest score.(in C++)
Write a program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
Write a program that prompts the user to enter a string and displays the number of...
Write a program that prompts the user to enter a string and displays the number of characters it contains, fourth character, and last character. Note: The string may contain blanks. For example: “C++ programming is fun”. You should write a complete program.
Write a program that prompts the user to enter time in 12-hour notation. The program then...
Write a program that prompts the user to enter time in 12-hour notation. The program then outputs the time in 24-hour notation. Your program must contain three exception classes: invalidHr, invalidMin, and invalidSec. If the user enters an invalid value for hours, then the program should throw and catch an invalidHr object. Follow similar conventions for the invalid values of minutes and seconds. This needs to be done in C++ There needs to be a separate header file for each...
Write a program that prompts the user for a number from 1 to 200 until 113...
Write a program that prompts the user for a number from 1 to 200 until 113 is encountered. Not including the 113, calculate the average. Do this in python. DO NOT USE LISTS!
Write a python program that calculates the area of triangle. The user will be asked to...
Write a python program that calculates the area of triangle. The user will be asked to enter the base (b) and the height (h). The formula to calculate the area is: Triangle_area=(bh)/2 Note: the program should print the area to the user: (for example: the area of the triangle is: 34.3)
(8 marks) Write a program to ask user to input an integer and display the special...
Write a program to ask user to input an integer and display the special pattern accordingly. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use loop statements (for, while or do-while). Your program should use only the following 3 output statements, one of EACH of the followings: System.out.print("-"); // print # System.out.print("+"); // print + System.out.println(); // print a newline Your code must work exactly like the following example (the text in bold...
In the main(), below, write a program that prompts for (1) how many values to sum,...
In the main(), below, write a program that prompts for (1) how many values to sum, and then (2) uses a summing loop to prompt for and add up 5 numbers. #include <iostream> #include <iomanip> using namespace std; int main() {     < your answer goes here> return 0; }
Write a C program, called logic_abc.c, that prompts the user to enter three integers a, b,...
Write a C program, called logic_abc.c, that prompts the user to enter three integers a, b, c, and then computes the results of the following logical operations, in sequence: !a || !b++ && c (a-1 || b/2) && (c*=2) (a-- || --b) && (c+=2) a || !(b && --c)
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT