Kodeclik Logo

Our Programs

Courses

Gifting

Learn More

Schedule

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.

math.tan() function in Python

Consider the following program:

import math

print("Tangent of " + str(0) + " degrees is " 
                    + str(math.tan(0)))
print("Tangent of " + str(90) + " degrees is " 
                    + str(math.tan(90*math.pi/180)))

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:

Tangent of 0 degrees is 0.0
Tangent of 90 degrees is 1.633123935319537e+16

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.

Kodeclik sidebar newsletter

Join our mailing list

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

About

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.

Copyright @ Kodeclik 2024. All rights reserved.