Skip to content

Instantly share code, notes, and snippets.

@fakruboss
Created July 8, 2017 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakruboss/c7e145c5eacbcecd9a000bdb33f4badb to your computer and use it in GitHub Desktop.
Save fakruboss/c7e145c5eacbcecd9a000bdb33f4badb to your computer and use it in GitHub Desktop.
def binary_search(first,last,count):
guess=int((first+last)/2)
print (guess)
opt=int(input())
if opt==1:
print ("Count: "+str(count))
print ("Correct guess")
elif opt==2:
print ("Count: "+str(count))
binary_search(first,guess,count+1)
else:
print ("Count: "+str(count))
binary_search(guess,last,count+1)
print ("Press 1.Correct 2.High 3.Low")
first=0
last=100
count=1
binary_search(first,last,count)
@fakruboss
Copy link
Author

Guessing Game Two (http://www.practicepython.org/exercise/2015/11/01/25-guessing-game-two.html)
Exercise 25

You, the user, will have in your head a number between 0 and 100. The program will guess a number, and you, the user, will say whether it is too high, too low, or your number.

At the end of this exchange, your program should print out how many guesses it took to get your number.

As the writer of this program, you will have to choose how your program will strategically guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment