In: Computer Science
Use Python to solve each problem. Answers should be written in full sentences.
Define a code that will give users the option to do one of the following.
Convert an angle from radians to degrees,
Convert an angle from degrees to radians,
Return the sine, cosine, or tangent of a given angle (need to know if angle is given in degrees or radians).
PYTHON PROGRAM:
import math
#options to choose operation from...
print("\nchoose any one of the following operations:")
print("1 convert an angle from degree to radian\n2 convert an angle from radian to degree")
print("3 find sine of angle\n4find cosine of angle\n5 find tangent of angle")
#input option
n=int(input())
print()
#taking input of angle
x=float(input("Enter angle: "))
print()
#conditions and calculations for corresponding options
if n==1:
print("In radian: ",round(x*math.pi/180,6)) #degree to radian upto 6 decimal place
elif n==2:
print("In degree: ",round(x*180/math.pi,6)) #radian to degree upto 6 decimal place
#options to find sine, cosine or tangent
elif n==3 or n==4 or n==5:
#input for type of angle i.e. degree or radian
t=int(input("Choose type of input:\n1 degree\n2radian\n"))
print()
#if degree type
if t==1:
if n==3:
print("sine of angle: ",round(math.sin(x*math.pi/180),6)) #sine of degree upto 6 decimal places
elif n==4:
print("cosine of angle: ",round(math.cos(x*math.pi/180),6)) #cosine of degree upto 6 decimal places
elif n==5:
print("tangent of angle: ",round(math.tan(x*math.pi/180),6)) #tangent of degree upto 6 decimal places
#if radian type
if t==2:
if n==3:
print("sine of angle: ",round(math.sin(x),6)) #sine of radian upto 6 decimal places
elif n==4:
print("cosine of angle: ",round(math.cos(x),6)) #cosine of radian upto 6 decimal places
elif n==5:
print("tangent of angle: ",round(math.tan(x),6)) #tangent of radian upto 6 decimal places
SAMPLE OUTPUT:
a.)
b.)