Skip to content

Instantly share code, notes, and snippets.

@mariack
Created March 26, 2015 01:11
Show Gist options
  • Save mariack/5c9c124980d75ad504ab to your computer and use it in GitHub Desktop.
Save mariack/5c9c124980d75ad504ab to your computer and use it in GitHub Desktop.
def main():
correctNum = int(input("Enter an integer between 1 and 99 for the computer to guess:"))
print("The number to guess is %d. SHHHH!!!!" % correctNum)
minVal = 1
maxVal = 99
guess = avgVal(minVal, maxVal)
attempts = 0
stop = False
while not stop:
attempts+=1
print("Attempt %d." % attempts)
print("Is it %d?" % guess)
hotCold = input("Enter +,-,= to tell me higher, lower, or equal:")
if hotCold == "+":
minVal = guessLow(guess)
guess = avgVal(minVal, maxVal)
elif hotCold == "-":
maxVal = guessHigh(guess)
guess = avgVal(minVal, maxVal)
elif hotCold == "=":
stop = True
print("Got it!!")
return
def avgVal(low, high):
average = int((.5)*(low + high))
return average
def guessLow(estimate):
lower = estimate + 1
return lower
def guessHigh(estimate):
higher = estimate - 1
return higher
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment