title: Using recursion to calculate Log in Python
body: <pre><code>def recursivelog(n, x, b):
      assert n &gt;= 0
      assert x &gt;= 1
      assert isinstance(b, int) 
      assert b &gt;= 2
      float(x)  # this statement does not change x so is useless here
      if(x &lt; b):
          return 0
      else:
          return 1+ recursivelog(n-1, x/b, b)
  </code></pre>
  
  <p><code>n</code>  indicates the number of steps (or recursive calls)</p>
  
  <p><code>x</code> the number for which to compute the logarithm</p>
  
  <p><code>b</code> the base of the logarithm</p>
  
  <p>While the result will round to the nearest positive integer like </p>
  
  <pre><code>&gt;&gt;&gt; recursivelog(100, 3)
  4
  </code></pre>
  
  <p>How to get a real number result?</p>