Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Level 1: Assignment 10 - Functions In Assignment 9 you created a calculat

ID: 3733191 • Letter: P

Question

Python Level 1: Assignment 10 - Functions

In Assignment 9 you created a calculator that output among other things the sine, cosine, and tangent of a number in radians. For this assignment I want you to output the value in degrees also.

Required

Create a function called rad2deg that takes as an argument the value in radians to convert. When the sine, cosine, and tangent functions are selected you will output the value in both radians and degrees. You must use the rad2deg function to convert the value.

Converting

The formula for converting radians to degrees is: degrees = radians * 180 / pi

Using the math constant

As most of us know PI is a constant value that is 3.14159 or larger depending on how much precision is required. The math class has pi defined within it which makes it nice for you. To use anything from the math class you need to import math.

Once you have done this you can simply plug pi into the formula:

degrees s= radians * 180 / math.pi

What not to do

using global variables

using print in the rad2deg function

using input in the rad2deg function

Your program should function like the following:

C:WINDOWS system32cmd.exe This caluclator requires you to enter a function and a number The functions are as follows: s - sine C - cosine - tangent R square root N- natural log x- eXit the program Please enter a function an a value: S 33 The sine of your number is e.9999118601072672 The sine of your number in degrees is 57.29072946922199 Please enter a function an a value: T 34 The tangent of your number is 0.6234989627162255 The tangent of your number in degrees is 35.72385909442439 Please enter a function an a value : X 0 Thanks for using the calculator Press any key to continue .. .

Explanation / Answer

#there are a lot of problems with the question, the sin and tan output shown are wrong, also, the value of sin cos tan should be equal for the same angle in radians or degree. #please provide assignment 9 code import math def rad2deg(r): return (r*180)/math.pi print('This calculator requires you to enter a function and a number') print('The functions are as follows:') print(''' S - sine C - cosine T - tangent R - square root N - natural log X - exit the program''') f=1 while f!='X': ip = input(' Please enter a function and a value: ') ip = ip.split() f = ip[0] num = float(ip[1]) if f=='S': print('The sine of your number is',math.sin(num)) print('The sine of your number in degrees is', math.sin(rad2deg(num))) elif f=='C': print('The cosine of your number is',math.cos(num)) print('The cosine of your number in degrees is', math.cos(rad2deg(num))) elif f=='T': print('The tangent of your number is',math.tan(num)) print('The tangent of your number in degrees is', math.tan(rad2deg(num))) elif f=='R': print('The square root of your number is',math.sqrt(num)) elif f=='N': print('The natural log of your number is',math.log(num)) print('Thanks for using the calculator')