Why does loop never exit?
<p>I have been working on a Bisectional Number guessing game and I would like to make it work automatically, but the code appears to be getting stuck in a loop. </p>

<p>Any suggestions?</p>

<pre><code>x = 75

low = 0
high = 100

guessing = True

while guessing:

    guess = int((high + low) // 2)

    if guess == x:
        guessing = False
    elif guess &lt; x:
        high = guess
    else:
        low = guess

print("Your number is ", str(guess))   
</code></pre>

<p>For such things it's better to limit the number of possible iterations. </p>

<pre><code>max_iter = 25
x = 42
low , high = 0 , 100

for _ in range(max_iter):
    guess = (high + low) // 2
    if guess == x:
        break
    low , high = (guess , high) if x &gt; guess else (low , guess)

print("Your number is {}".format(guess))   
</code></pre>

python python-3.x