Login Register


[Python] Guess your number filter_list
Author
Message
RE: [Python] Guess your number #16
Code:
low = 0 high = 100 ans = (high + low)/2 print("Please think of a number between 0 and 100!") while True: print("Is your secret number "+str(ans)+"?") x = raw_input("Enter 'h' to indicate the guess istoo high. \ Enter 'l' to indicate the guess is too low. \ Enter 'c' to indicate I guessed correctly. ") if x == 'h': high = ans elif x == 'l': low = ans elif x == 'c': break else: print("Sorry, I did not understand your input.") ans = (high + low)/2 print("Game over. Your secret number was: "+str(ans))

I think this is a good way as well, instead of random I use bisection search, - in this program I do not count the tries but I can write it in if it's necessary - . I'm a newbie so correct me if I'm wrong, but using this method will get the guessed number faster sometimes.Wink
I wasn't a hacker for the money, and it wasn't to cause damage.
~ Kevin Mitnick

Reply





Messages In This Thread
[Python] Guess your number - by chmod - 02-09-2013, 02:18 PM
[Python] Guess your number - by chmod - 02-09-2013, 02:18 PM
[Python] Guess your number - by chmod - 02-09-2013, 02:18 PM



Users browsing this thread: