Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Guessing game
- def guessing_game(min, max):
- print("Think of a number between {} and {}".format(min, max))
- count=0
- done = False
- def plural(count):
- if count == 1:
- return ""
- else:
- return "es"
- while done == False:
- count=count+1
- middle = int((max + min)/2)
- 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:
- print("Your number is {}, it took me {} guess{}".format(middle, count, plural(count)))
- done = True
- guessing_game(1, 100)
Advertisement
Add Comment
Please, Sign In to add comment