This post will demonstrate the use of the math module for computing the sine and cosine of an angle. For reference to the math module, I use the following link:
https://docs.python.org/2/library/math.html
From this link, we can see the coding for the cosine and sine functions:
In our code, we will be asking the user for an angle in degrees. Since the cos and sin functions use radians, we will need to convert. You can do this by multiplying the degrees by (pi / 180). Alternatively, we can use another math function to perform this computation:
In our code, we import the math module in order to be able to access the math functions. We then ask the user for the angle in degrees, convert to radians, and then compute and print the cosine and sine of that angle. Remember to specify that the object, "angle", is a float since that is what is expected in the math functions. The code is as follows:
https://docs.python.org/2/library/math.html
From this link, we can see the coding for the cosine and sine functions:
In our code, we import the math module in order to be able to access the math functions. We then ask the user for the angle in degrees, convert to radians, and then compute and print the cosine and sine of that angle. Remember to specify that the object, "angle", is a float since that is what is expected in the math functions. The code is as follows:
The results of the simulation of this code are shown below:
Comments
Post a Comment