Let's calculate sine, cosine and tangent in Python. It is not a difficult task, but it requires attention to some details.
First of all, we need to import the math
library:
import math
Next, we need to read the angle value the user will enter. But an important note, the calculation requires the angle value in radians.
So, just perform this conversion from angle to radians. How? Using the radians()
method from the math
library:
ang = int(input('Angle: '))
rad = math.radians(ang)
With the angle value in radians, we can now calculate the sine, cosine and tangent values. We'll use the sin()
, cos()
and tan()
methods from the math()
library:
sine = math.sin(rad)
cosine = math.cos(rad)
tangent = math.tan(rad)
Top comments (0)