tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,29 @@
inclusive_range = mn, mx = (1, 10)
print('''\
Think of a number between %i and %i and wait for me to guess it.
On every guess of mine you should state whether the guess was
too high, too low, or equal to your number by typing h, l, or =
''' % inclusive_range)
i = 0
while True:
i += 1
guess = (mn+mx)//2
txt = input("Guess %2i is: %2i. The score for which is (h,l,=): "
% (i, guess)).strip().lower()[0]
if txt not in 'hl=':
print(" I don't understand your input of '%s' ?" % txt)
continue
if txt == 'h':
mx = guess-1
if txt == 'l':
mn = guess+1
if txt == '=':
print(" Ye-Haw!!")
break
if (mn > mx) or (mn < inclusive_range[0]) or (mx > inclusive_range[1]):
print("Please check your scoring as I cannot find the value")
break
print("\nThanks for keeping score.")

View file

@ -0,0 +1,19 @@
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)