finding cubed root using delta and epsilon in Python
<p>I am trying to write a program that finds cubed root using delta and epsilon but i'm stuck because i cant figure out why my program runs in an infinite loop</p>

<pre><code>    num = 100

    epsilon = 0.01
    guess = num/3.0


    while abs(guess**3 - num) &gt;= epsilon:
        delta = abs(guess**3 - num)/100
        if guess**3 &gt; num:
            guess = (guess - delta)
        if guess**3 &lt; num:
            guess = (guess + delta)
    print("Guess:", guess)
</code></pre>

<p>First thing, you should use <code>if/elif</code> instead of separate <code>if</code> blocks. </p>

<p>Consider the following:
when <code>guess**3 &gt; num</code> is <code>True</code>, you update <code>guess</code> by reducing its value so that <code>guess**3 &lt; num</code> (the next if condition) becomes <code>True</code> again, which reverses the initial update. In summary, the value of <code>guess</code> is never changed in that loop, and the loop whirls to infinity.</p>

<p>Secondly you want to regularize the <code>delta</code> value (penalize it) as it can be come alarming large as the value of <code>num</code> increases.</p>

<pre><code>num = 100

epsilon = 0.01
guess = num/3.0

while abs(guess**3 - num) &gt;= epsilon:
    delta = abs(guess**3 - num)/num
    if guess**3 &gt; num:
        guess = (guess - delta*epsilon**0.5)
    elif guess**3 &lt; num:
        guess = (guess + delta*epsilon**0.5)
print("Guess:", guess)
</code></pre>

python python-3.x