[ create a new paste ] login | about

Link: http://codepad.org/5HbjI6Af    [ raw code | fork ]

Python, pasted on Feb 10:
def show_guess(number):
    print "My guess is %d" % number
    print "Is that [c]orrect, too [h]igh, or too [l]ow?"
    return raw_input();

def game():
    guess = 50
    high  = 100
    low   = 0 
    count = 0

    result = show_guess(guess)
    while(result != 'c'):
        count += 1

        if(result == 'l'):
            low = guess
            guess += (high - low) / 2
        elif(result == 'h'):
            high = guess
            guess -= (high - low) / 2
        else:
            print "Invalid input!"
        
        result = show_guess(guess)

    print "I guessed your number in %d guesses :)" % count

print "Think of a number between 1 and 100 and I will try to guess it..."
raw_input("Press ENTER when you're ready!")
game()
raw_input()


Create a new paste based on this one


Comments: