Advertisement
GCK

GCK/ guessing game_relook

GCK
Sep 23rd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. print("Think of a number between 1 and 100")
  2.  
  3.    
  4. def IGuessYourNumber():
  5.         max = 101
  6.         min = 0
  7.        
  8.         counter=0
  9.         myGuess=False
  10.         while myGuess==False:
  11.             middle = int((max + min)/2)
  12.             answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle)).upper()
  13.             if answer == "H":
  14.                 min = middle
  15.                 counter+=1
  16.             elif answer == "L":
  17.                 max = middle
  18.                 counter+=1
  19.             else:
  20.                 print("Your number is {}, it took me {} guess".format(middle,counter+1))
  21.                 myGuess=True
  22.                 #quit()
  23.  
  24. IGuessYourNumber()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement