Kodeclik Blog

math.tan() in Python

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!
Now that you have mastered the math.tan() function, checkout the math.ceil() and math.floor() functions! Also learn about the math domain error in Python and how to fix it!
Interested in more things Python? Checkout our post on Python queues. Also see our blogpost on Python's enumerate() capability. Also if you like Python+math content, see our blogpost on Magic Squares. Finally, master the Python print function!
Want to learn Python with us? Sign up for 1:1 or small group classes.

Join our mailing list

Subscribe to get updates about our classes, camps, coupons, and more.

Copyright @ Kodeclik 2023. All rights reserved.