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>I think it will work:</p>

<pre><code>x = 75
low = 0
high = 100
guessing = True
while guessing:
    guess = (high + low) // 2
    print("guess:",guess)
    if guess == x:
        guessing = False
    elif guess &lt; x:
        low = guess
    else:
        high = guess
print("Your number is ", guess) 
</code></pre>

<p>output:  </p>

<pre><code>guess: 50
guess: 75
Your number is  75
</code></pre>

<p>You don't need to explicitly convert it to int because you are using integer division here  <code>guess = int((high + low) // 2)</code> And reverse the <code>elif ..else</code> logic..</p>

<p>Hope this will help you.</p>

python python-3.x