print "Please think of a number between 0 and 100!" upperbound = 100 lowerbound = 0 while True: mid = (upperbound - lowerbound)/2 + lowerbound print "Is your secret number %s?" % mid guess = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.") if guess == 'h': upperbound = mid elif guess == 'l': lowerbound = mid elif guess == 'c': print 'Game over. Your secret number was: ' + str(mid) break else: print 'Sorry, I did not understand your input.'
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question