Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Think of a number between 1 and 100, both inclusive.")
- def guess(min, max):
- count = 0 # if I begin at 1, it adds a guess to the total number of guesses
- while True:
- middle = int((max + min)/2)
- # with upper, the user can use lower and capital letters
- count = count + 1
- answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}? ".format(middle)).upper()
- if answer == "H":
- min = middle
- elif answer == "L":
- max = middle
- else:
- # if I include str(count) in the print, the format function goes crazy and mixes the numbers
- print("Your number is {}, it took me {} guesses".format(middle, count))
- quit()
- guess(0, 101)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement