How to find tan^2(30) in python?

Question:

I wanted to find tan^2(x) in Python and it is different from tan(x)^2 which can be found using the following:

(math.tan(30))**2
Asked By: Dvarkesh

||

Answers:

Your Python expression is the correct way to calculate tan2 30, but that is the squared tangent of 30 radians.

You probably want the squared tangent of 30 degrees, so you need to convert degrees to radians. You can do the conversion yourself:

>>> (math.tan(30 * math.pi / 180))**2
0.33333333333333315

Or you can use math.radians:

>>> math.tan(math.radians(30))**2
0.33333333333333315
Answered By: rob mayoff
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.