ln (Natural Log) in Python
<p>In this assignment I have completed all the problems except this one. I have to create a python script to solve an equation (screenshot).</p>

<p><a href="http://i.stack.imgur.com/vFEwQ.gif" rel="nofollow"><img src="http://i.stack.imgur.com/vFEwQ.gif" alt="formula"></a></p>

<p>Unfortunately, in my research all over the internet I cannot figure out how in the world to either convert ln to log or anything usable, or anything. The code I have written so far is below. I will also post the answer that our teacher says we should get.</p>

<pre><code>import math
p = 100
r = 0.06 / 12
FV = 4000

n = str(ln * ((1 + (FV * r) / p) / (ln * (1 + r))))

print ("Number of periods = " + str(n))
</code></pre>

<p>The answer I should get is 36.55539635919235
Any advice or help you have would be greatly appreciated!</p>

<p>Also, we are not using numpy. I already attempted that one.</p>

<p>Thanks!</p>

<p><code>math.log</code> is the natural logarithm:</p>

<p><a href="https://docs.python.org/2/library/math.html" rel="nofollow">From the documentation:</a></p>

<blockquote>
  <p>math.log(x[, base]) With one argument, return the natural logarithm of
  x (to base e).</p>
</blockquote>

<p>Your equation is therefore:</p>

<pre><code>n = math.log((1 + (FV * r) / p) / math.log(1 + r)))
</code></pre>

<p>Note that in your code you convert n to a <code>str</code> twice which is unnecessary</p>

python python-2.7 natural-logarithm