import random print("Think of an integer between 1 and 1000") #upper/lower bounds inclusive upper = 1000 lower = 1 complete = False i= 0 while(i < 9): mid = (upper+lower)/2 ans = raw_input("Is your number equal to, greater than, or less than " + str(mid) + "? ") if(ans.find("equal") != -1): print "Great! Your number is " + str(mid) complete = True break elif (ans.find("greater") != -1 or ans.find("higher") != - 1): lower = mid + 1 elif (ans.find("less") != -1 or ans.find("lower") != -1): upper = mid - 1 else: print "Are you alright? Try again" continue i += 1 guess = random.randint(lower, upper) if(not complete): while True: ans = raw_input("Question 10: Is your number equal to " + str(guess) +"? T or F? ") if (ans.find("T") != -1): print "Great!" break; elif (ans.find("F") != -1): print "Really?" real = input("What was your number? ") if (real > upper or real < lower): print "Liar, liar, pants on fire! Based on what you told me, your name was greater than or equal to", lower, "but less than or equal to", upper elif real == guess: print "That's what I said, numbnuts!" else: print "Well...you bested me!" break; else: "Seriously dude? It's T or F. Super simple."