Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Guessing Game by Chris
- max = 101
- min = 0
- counter = 0
- end = True
- print("Think of a number between 1 and 100")
- # guess function
- def guess_fn(max,min,counter,end):
- middle = int((max + min)/2)
- answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}? ".format(middle)).upper()
- counter = counter+1
- if answer == "H":
- min = middle
- elif answer == "L":
- max = middle
- else:
- if counter==1: #get the plural right
- print("Your number is {}, it took me {} guess".format(middle,counter))
- else:
- print("Your number is {}, it took me {} guesses".format(middle,counter))
- end = False #end while loop
- return(max,min,counter,end)
- # run loop
- while end:
- max,min,counter,end = guess_fn(max,min,counter,end) #trial
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement