Question

In: Computer Science

22.8 LAB 5 D FALL 19 : Using math functions This lab problem demonstrates the use...

22.8 LAB 5 D FALL 19 : Using math functions

This lab problem demonstrates the use of import module. The Python programming language has many strengths, but one of its best is the availability to use many existing modules for various tasks, and you do not need to be an experienced computer programmer to start using these modules.

We have given you some incomplete code; note that the very first line of that code contains an import statement as follows:

import math

This statement enables your program to use a math module. A module is a collection of instructions saved together as a whole. So, in this lab you are using the math module. Any time we choose to use a module, we must use an import statement to bring this module into the program. When we import the math module, all the computer instructions contained in the math module are made available to our program, including any functions that have been defined.

If you are interested in finding out what is in the math module you can always go to the Python docs and take a look: Python Docs

Example of using the math module:
print(math.floor(5.4))
will use the floor() function as defined in the math module, and in this case with the argument 5.4, will result in printing the value 5.

Below is the definition of your problem that we are asking you to solve using the math module.

Prompt the user for floating point numbers x, y and z. For the x value your you will the use the following prompt Enter x value:inside of your input statement. Using the same approach you will prompt the user for y and z.

- Given three floating-point numbers x, y, and z, 
your job is to output
     - the **square root** of x,
     - the **absolute value** of (y minus z) , and 
     - the **factorial** of (the **ceiling** of z).  

Example of a sample run:

Enter x value:5

Enter y value:6.5

Enter z value:3.2

Then the expected output from these entries is:

2.23606797749979 3.3 24

Hint: For finding out the square root you will need to use math.sqrt(), you need to use the website recommended above to find out which functions to use in order to solve the rest of the lab problem.

Solutions

Expert Solution

import math

x = float(input('Enter x value: '))
print()
y = float(input('Enter y value: '))
print()
z = float(input('Enter z value: '))

squart_root_x = math.sqrt(x) #the **square root** of x,
absolute_diff = abs(z - y) #the **absolute value** of (y minus z) ,
factorial_z = math.factorial(math.ceil(z)) #the **factorial** of (the **ceiling** of z).

print()
print(squart_root_x, absolute_diff, factorial_z)


Related Solutions

In this lab assignment, students will demonstrate the abilities to: - Use functions in math module...
In this lab assignment, students will demonstrate the abilities to: - Use functions in math module - Generate random floating numbers - Select a random element from a sequence of elements - Select a random sample from a sequence of elements (Python Programming) NO BREAK STATEMENTS AND IF TRUE STATEMENTS PLEASE Help with the (create) of a program to play Blackjack. In this program, the user plays against the dealer. Please do the following. (a) Give the user two cards....
This lab problem demonstrates the use of import module. The Python programming language has many strengths,...
This lab problem demonstrates the use of import module. The Python programming language has many strengths, but one of its best is the availability to use many existing modules for various tasks, and you do not need to be an experienced computer programmer to start using these modules. We have given you some incomplete code; note that the very first line of that code contains an import statement as follows: import math This statement enables your program to use a...
JAVA Lab Assignment #13:  Looping Lab with both types of loops. This lab demonstrates the use of...
JAVA Lab Assignment #13:  Looping Lab with both types of loops. This lab demonstrates the use of the While Loop and the Do While Loop as error checking mechanisms. You will be using each of these loops to solve the same problem. Please put them both in the same program. When you test the code, you will not see a difference in the way they execute - but there will be a difference in the logic when writing the code. You...
using math lab, Write a code to compute the change in dollars (no cents) to be...
using math lab, Write a code to compute the change in dollars (no cents) to be given back to a restaurant patron who pays the bill in cash. That is, find and enumerate the various combinations (of common currency notes only) that can amount to the change due.
This problem demonstrates the concept of redundancy, the principle of improving reliability of systems by using...
This problem demonstrates the concept of redundancy, the principle of improving reliability of systems by using redundant or backup components. Suppose a hydraulic system on an airplane has a 5% probability of failing. Now, suppose that the airplane has three independent hydraulic systems that each have a 5% probability of failure Supposing that the airplane will safely complete its flight if at least one of the three independent hydraulic systems is functioning, what is the probability that the airplane will...
BUSI 320 Comprehensive Problem 3 FALL D Use what you have learned about the time value...
BUSI 320 Comprehensive Problem 3 FALL D Use what you have learned about the time value of money to analyze each of the following decisions: Decision #1: Which set of Cash Flows is worth more now? Assume that your grandmother wants to give you generous gift. She wants you to choose which one of the following sets of cash flows you would like to receive: Option A: Receive a one-time gift of $10,000 today. Option B: Receive a $1400 gift...
The number of students using the math lab per day is found in the distribution below....
The number of students using the math lab per day is found in the distribution below. Find the mean, variance, and standard deviation for this probability distribution ? 6 8 10 12 14 ?(?) 0.15 0 0.35 0.1 … Find the (i) Missing probability
Need to use math lab for the Isim function for calculating the output and state response....
Need to use math lab for the Isim function for calculating the output and state response. Of the Transfer Function s + 2 / s^2 + 2 s + 2. I been using the following code and it doesn’t work sys = tf([1 2],[1 2 2]) t = [0:0.01:]; u=0*t; [y,T,x] = lsim(sys,u,t) subplot(121), plot(T,x(:,1)) xlabel('Time(s)'),ylabel('x_1') subplot(122),plot(T,x(:,2)) xlabel('Time(s)'),ylabel('x_2')
In this lab you will learn how to use methods from the Math class in order...
In this lab you will learn how to use methods from the Math class in order to calculate the area or the volume of several different shapes. If you are confused about the Methods you can access from the Math class and would like to see some examples click here. Hint: Most of these methods can be done in one line. Step 1 - circleArea In this method you will calculate the area of a circle. Before you can calculate...
excel problem Find the roots of the functions given using the bisection method. Use the graph...
excel problem Find the roots of the functions given using the bisection method. Use the graph of each function to choose points that bracket the root of interest. a. f(x) x-x^1/3-2 b.f(x)=xtanx-1 c.f(x)=x^4-e^x+1 d.f(x)x^2e^x-1
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT