Question
Python Level 1: Assignment 9 - Primed Loops Math Calculator Create a math calculator that will compute the following functions: Sine Cosine Tangent Square Root
Python Level 1: Assignment 9 - Primed Loops
Math Calculator
Create a math calculator that will compute the following functions:
Sine
Cosine
Tangent
Square Root
Natural Log
Your program will take a string which represents the function to perform and the value to perform the function on using the following specification:
S - sine
C - Cosine
T - Tangent
R - Square Root
N - Natural Log
X - exit the program
The numeric input for your program should be of type float. The program will continue to take input and calculate until the 'X' character is input for the function.
Your input should be in the following form
T 32.0
This should yield the tangent of 32.0 in radians.
You may be wondering how you are going to compute all of this. Fortunately for us python comes with all of these math functions included. To use the functions you need to import math. The following is a list of the functions in cmath you will need to accomplish the task:
Description | Usage |
float math.sin(float val) | x = math.sin(32.0) |
float math.cos(float val) | x = math.cos(40.0) |
float math.tan(float val) | x = math.tan(20.2) |
float math.sqrt(float val) | x = math.sqrt(9.0) |
float math.log10(float val) | x = math.log10(10) |
Here is an example program that demonstrates the use of the sin function:
import math
val = float(input('Enter a value: '))
theSine = math.sin(val) print('The sine in radians is',theSine)
Notice that the function produces the sine of the value provided. Inside the parentheses you supply the value you want the sine for. This value is called an argument or parameter for the function. Also notice you simply assign what the function produces to a variable.
Required:
You must prime the loop properly. If you are unsure ask or go back to the lecture material on priming loops.
Your program should run like the following:
Side note: we must use a while loop that allows the user to choose their function, aka using multiple choice.
C:\WINDOWS\system32cmd.exe This caluclatorrequires you to enter a function and a number The functions are as follows: C - cosine T - tangent R square root N - natural log x - eXit the program Please enter a function an a value: t 45 The tangent of your number is 1.6197751905438615 Please enter a function an a value: s 32 The sine of your number is .551426681241696 Please enter a function an a value: xe Thanks for using the calculator Press any key to continueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started