Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Guessing Game
- import time
- def numberGuess(min, max): #trying to think of making the program more robot using the min, max but if declared in the program it isn't necessary per se
- guesses = 1 #added a guess counter so I can put the program in a loop instead of repeating code
- while guesses < 8: #loop of 8 guesses, as per original program
- middle = int((max + min)/2)
- answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}? ".format(middle)).upper() #added a ?
- if answer == "H":
- min = middle
- elif answer == "L":
- max = middle
- else:
- print("Your number is {}, it took me".format(middle), guesses, "guesses") #reformatted so that this works in my loop style
- time.sleep(1)
- quit()
- guesses += 1 #increases guess counter so that the game ends appropriately
- print("Your number is {}, it took me 8 guesses".format(middle))
- time.sleep(1)
- quit()
- print("Think of a number between 1 and 100")
- time.sleep(1)
- numberGuess(0, 100)
- #I'm thinking a better version of this would be to strip out JUST the number check, then use the number check function in the main program, in a loop...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement