# binguess 
# Fig. 45.1 

import random

MAX = 100

left = 1
right = MAX
numGuesses = 0
print("Think of a number between 1 and " + str(MAX))
print("I will guess it, based on a few questions...")
while left != right:
  mid = (left + right)//2
  numGuesses += 1
  reply = input("Is it <= "+ str(mid) + " (answer y/n)? ")
  if reply.lower()[0] == 'y':
    right = mid
  else:
    left = mid+1
print("x =", right, "; no. guesses =", numGuesses)
