title: Finding the square root of a number using bisection method
body: <p>I have tried to find the square root of a number such that </p>
  
  <pre><code> abs(y**2-x) &lt; epsilon 
  </code></pre>
  
  <p>using the bisection method, however, I don't get the answer I want when I run it. If I choose x to be 4 and 0.01, I expect to get 2, but instead, I get 1.0. Can anyone please help me fix this?</p>
  
  <p>Test Case:</p>
  
  <pre><code> &gt; squareRoot(4, 0.01)
   &gt; 1.0
  </code></pre>
  
  <pre class="lang-py prettyprint-override"><code>def squareRoot(x, epsilon):
      low = 0
      high = max(1.0, x)
      y = (high+low) / 2.0
      while abs(y**2 - x)&lt;epsilon:
          if y**2 &lt; x:
              low = y
          else:
              high = y
          y = (high + low) / 2.0
      return y
  </code></pre>