Calculating Sine, Cosine and Tangent in Python

udanielnogueira

Daniel Nogueira

Posted on November 5, 2022

Calculating Sine, Cosine and Tangent in Python

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
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
udanielnogueira
Daniel Nogueira

Posted on November 5, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related