Recall that the tangent of an angle is defined as the opposite side (opposite to the angle) divided by the adjacent side in a right-angled triangle. The tan() ratio is the sine divided by the cosine.
It is well known that the tangent of zero degrees is zero and the tangent of 90 degrees (which is pi/2 radians) is undefined (because the cosine of that angle is zero). The Math.tan() is a handy function in Python to compute these trigonometric ratios.
Consider the following program:
Note that in the second line we are careful to convert degrees to radians (by scaling by pi/180) before passing the result to the sin() function. (In the first line, we know that 0 degrees is the same as 0 radians, so we do not need to be so careful.)
The output is:
Also note that in the second output we get a ridiculously large number (to be interpreted as infinity).
In conclusion, you can use the Math.tan() function which is a built-in function in the Math module of Python.
If you liked learning about the math.tan() function, you should checkout our blogposts on the math.sin() and math.cos() functions!
Kodeclik is an online coding academy for kids and teens to learn real world programming. Kids are introduced to coding in a fun and exciting way and are challeged to higher levels with engaging, high quality content.