Created
July 8, 2017 05:19
-
-
Save fakruboss/c7e145c5eacbcecd9a000bdb33f4badb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.