math.cos(x) not returning correct value?
<p>I just started using python, and am having difficulty with a very basic program. I want to calculate the cosine of -20 degrees. It is my understanding that the default value is in radians, so this is the following code i tried:</p>

<pre><code>import math 


print math.cos(math.degrees(-20))
</code></pre>

<p>This outputs (-.7208...), where the answer is actually (.9397...). I'm sure this has a pretty basic solution but I've tried so many different things and it will not output the correct results. Thanks in advance!</p>

<p>Per the <a href="https://docs.python.org/3.5/library/math.html#angular-conversion" rel="nofollow">Python documentation</a>:</p>

<blockquote>
  <p><strong><code>math.degrees(x)</code></strong></p>
  
  <p>Convert angle <em>x</em> from radians to degrees.</p>
</blockquote>

<p>That means you are attempting to convert -20 radians to degrees which isn't desired.</p>

<p>Also per the documentation:</p>

<blockquote>
  <p><strong><code>math.cos(x)</code></strong></p>
  
  <p>Return the cosine of <code>x</code> radians.</p>
</blockquote>

<p>This means <code>math.cos</code> finds the cosine of the passed argument in <em>radians</em>, not degrees. That means your code currently changes -20 radians to degrees, then finds the cosine of that as if it were radians... you can see why that's a problem.</p>

<p>You need to convert -20 degrees to radians, and then find the cosine. Use <a href="https://docs.python.org/3.5/library/math.html#angular-conversion" rel="nofollow"><code>math.radians</code></a>:</p>

<pre><code>math.cos(math.radians(-20))
</code></pre>

python math trigonometry