$ python guess.py
Is your choice 7? l
Is it 4? l
How about 2? h
Oh! I know it! Your number was 3 !
YAY! I got it!!! And it only took 3 guesses!
Please hit Return
$ python guess.py
Is your choice 7? z
Ahem. Please. 'l' 'm' or 'y' aka 'less' 'more' or 'yes': w
Ahem. Please. 'l' 'm' or 'y' aka 'less' 'more' or 'yes': x
Ahem. Please. 'l' 'm' or 'y' aka 'less' 'more' or 'yes': l
Is it 4? l
How about 2? h
Oh! I know it! Your number was 3 !
YAY! I got it!!! And it only took 3 guesses!
Please hit Return
Is your choice 7? zzz
Ahem. Please. 'l' 'm' or 'y' aka 'less' 'more' or 'yes': zzz
Hmmm.... is it 9? zzz
Ahem. Please. 'l' 'm' or 'y' aka 'less' 'more' or 'yes': zzz
Oh! I know it! Your number was 10 !
YAY! I got it!!! And it only took 2 guesses!
Please hit Return
min = 0
max = 10
found = false
count = 1
while found == false
guess = (max + min)/2
print Is your number $guess ?
input = getInput()
if input == "yes"
print "yay I got it in $count guesses"
found = true
elsif input == "lower"
max = input
count++
else
min = input
count++
end
end
print "game over"
if a.lower() in "l less f <>. (Some Perl idioms are good.)>if a.lower() in "l less f < blah blah".split()
possibleNumbers = [x for x in range(1,11)]
gotIt = False
guessCount = 0
while not gotIt:
guess = possibleNumbers[(len(possibleNumbers)/2)]
guessCount += 1
answer = raw_input("is it %d? " % guess)
while answer not in ['l','g','y']:
answer = raw_input('Huh? gimme a l/g/y')
if answer == 'l':
possibleNumbers = possibleNumbers[:possibleNumbers.index(guess)]
elif answer == 'g':
possibleNumbers = possibleNumbers[possibleNumbers.index(guess+1):]
elif answer == 'y':
print "Who's your momma! It only took me %d tries. Suck on that!" % guessCount
gotIt = True
You are not logged in, either login or create an account to post comments
posted by chrisamiller at 7:07 PM on February 4