复习 第二周 第三讲 Bisection search
Example <猜数字>:
print("Please think of a number between 0 and 100!")
low = 0
high = 100
for x in range(100):
x = (low + high)/2
print("Is your secret number " + str(x) +"?")
userinp = (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 userinp == 'c':
print "Game over. Your secret number was: " + str(x)
break
elif userinp == 'h':
high = x
elif userinp == 'l':
low = x
else:
print "Sorry, I did not understand your input."