Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Guessing Game
- max = 101
- min = 0
- tries = 0
- numFound = False
- print("Think of a number between 1 and 100 ")
- def middle (max , min):
- return int((max + min)/2)
- def findNum(max,min,tries):
- temp = middle (max , min)
- answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(temp))
- if answer.upper() == "H":
- min = middle (max , min)
- elif answer.upper() == "L":
- max = middle (max , min)
- elif answer.upper() == "S":
- return True , max , min , tries
- else :
- print("Invaled answer , answers must be 'H,L,S'")
- return False , max , min , tries
- tries=tries+1
- return False , max , min , tries
- while (numFound == False):
- numFound, max , min , tries = findNum(max,min,tries)
- print("Your number is {}, it took me {} guess".format(middle (max , min),tries))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement