RosettaCodeData/Task/Guess-the-number-With-feedback--player-/Python/guess-the-number-with-feedback--player--2.py
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

19 lines
650 B
Python

import bisect
try: input = raw_input
except: pass
class GuessNumberFakeList(object):
def __getitem__(self, i):
s = input("Is your number less than or equal to %d?" % i)
return 0 if s.lower().startswith('y') else -1
LOWER, UPPER = 0, 100
if __name__ == "__main__":
print("""Instructions:
Think of integer number from %d (inclusive) to %d (exclusive) and
I will guess it. After each guess, I will ask you if it is less than
or equal to some number, and you will respond with "yes" or "no".
""" % (LOWER, UPPER))
result = bisect.bisect_left(GuessNumberFakeList(), 0, LOWER, UPPER)
print("Your number is %d." % result)