Trigonometric functions: Difference between revisions

added python
m (→‎{{header|BASIC}}: Syntax highlighting)
(added python)
Line 311:
0.785398163397448 45
0.785398163397448 45
</pre>
 
=={{header|Python}}==
 
Python's <tt>math</tt> module contains all six functions. The functions all accept radians only, so conversion is necessary when dealing with degrees. The <tt>math</tt> module also has <tt>degrees()</tt> and <tt>radians()</tt> functions for easy conversion.
 
<python>import math
 
radians = math.pi / 4
degrees = 45.0
 
#sine
print math.sin(radians), math.sin(math.radians(degrees))
#cosine
print math.cos(radians), math.cos(math.radians(degrees))
#tangent
print math.tan(radians), math.tan(math.radians(degrees))
#arcsine
arcsin = math.asin(math.sin(radians))
print arcsin, math.degrees(arcsin)
#arccosine
arccos = math.acos(math.cos(radians))
print arccos, math.degrees(arccos)
#arctangent
arctan = math.atan(math.tan(radians))
print arctan, math.degrees(arctan)</python>
 
Output:
<pre>
0.707106781187 0.707106781187
0.707106781187 0.707106781187
1.0 1.0
0.785398163397 45.0
0.785398163397 45.0
0.785398163397 45.0
</pre>
 
Anonymous user