Daniel Nogueira
Posted on November 5, 2022
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)
💖 💪 🙅 🚩
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
python Mastering Python’s __name__ and __main__: Understanding Script Execution and Module Imports
November 1, 2024
raspberrypi Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi
October 6, 2024