In: Computer Science
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.
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)