Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Guessing Game
- print("Think of a number between 1 and 100")
- #average function which determines the middle number the computer should guess next
- def min_max(minimum, maximum):
- mid = int((minimum + maximum)/2)
- return mid
- #guess function which collects input from user to determine new guessing range
- def num_guess():
- guess = False
- max = 100
- min = 0
- count = 1
- while guess == False:
- middle = min_max(min, max)
- answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle)).upper()
- if answer == "H":
- min = middle
- count += 1
- elif answer == "L":
- max = middle
- count += 1
- else:
- print("Your number is {}, it took me ".format(middle) + str(count) + " guess(es)")
- guess = True
- num_guess()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement