Advertisement
chrisCNG

guessing2

Feb 22nd, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. # Guessing Game by Chris
  2.  
  3. max = 101
  4. min = 0
  5. counter = 0
  6. end = True
  7. print("Think of a number between 1 and 100")
  8.  
  9. # guess function
  10. def guess_fn(max,min,counter,end):
  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.     counter = counter+1
  14.     if answer == "H":
  15.         min = middle
  16.     elif answer == "L":
  17.         max = middle
  18.     else:
  19.         if counter==1: #get the plural right
  20.             print("Your number is {}, it took me {} guess".format(middle,counter))
  21.         else:
  22.             print("Your number is {}, it took me {} guesses".format(middle,counter))
  23.         end = False #end while loop
  24.     return(max,min,counter,end)
  25.  
  26. # run loop
  27. while end:
  28.     max,min,counter,end = guess_fn(max,min,counter,end) #trial
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement