#This program assumes you won't lie consecutively #I SPENT 7 HOURS ON THIS DONT TELL ME IM WRONG a = 0 b = 500 n = 1 L = 0 def smartbot(z): global a global b global n global L #pulling variables from the outside if (b-a) != 0 and (b-a) != 1: #run the program we're still to far from a good guess x = raw_input("Is the number between %d and %d inclusive?" %(a, b)) if x == "Y": if L !=0: #making sure the Lie detector doesn't go below 0 L = L-1 b = a+(b-a)/2 n = n+1 smartbot(smartbot) else: #alters a and b to ask for the bottom half of given range b = a+(b-a)/2 n = n+1 smartbot(smartbot) elif x == "N": if L == 1: #tests if the previous input was a No (two Nos in a row = lie) a = b - 1000/(2**(n-1)) print "You're lying!!!" smartbot(smartbot) else: #alters a and b to ask for the upper half of the previous range L = L+1 a = b+1 b = a-1 + 1000/(2**n) smartbot(smartbot) else: #forces you to input Y or N print "Please answer with Y or N" smartbot(smartbot) else: #one more step to whittle down x = raw_input("Is the number between %d and %d inclusive?" %(a, b)) if x == "Y": eitheror(smartbot) elif x == "N": a = a+2 b = b+2 eitheror(smartbot) def eitheror(z): #when we're sure it's either one of two variables y = raw_input("is the answer %d?" %(a)) if y == "Y": print "your answer is ", a,"." elif y == "N": print "your answer is ", b,"." def question(): z = raw_input("Think of a number between 0 and 1000. Press 'enter' when you have thought of a number.") return z question() smartbot(question)