def guessNumber(self, n): low = 1 high = n my_guess = n/2 while(guess(my_guess)!=0): if guess(my_guess) == 1: low = my_guess+1 my_guess = (high + low)/2 else: high = my_guess-1 my_guess = (high + low)/2 return my_guess
I don't like the fact that in each iteration you call the API twice.
It's not a great design habit.
@pisskidney You are right. Thanks!