Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. ## Guessing Game
  2. import time
  3. 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
  4. guesses = 1 #added a guess counter so I can put the program in a loop instead of repeating code
  5. while guesses < 8: #loop of 8 guesses, as per original program
  6. middle = int((max + min)/2)
  7. answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}? ".format(middle)).upper() #added a ?
  8. if answer == "H":
  9. min = middle
  10. elif answer == "L":
  11. max = middle
  12. else:
  13. print("Your number is {}, it took me".format(middle), guesses, "guesses") #reformatted so that this works in my loop style
  14. time.sleep(1)
  15. quit()
  16. guesses += 1 #increases guess counter so that the game ends appropriately
  17. print("Your number is {}, it took me 8 guesses".format(middle))
  18. time.sleep(1)
  19. quit()
  20.  
  21. print("Think of a number between 1 and 100")
  22. time.sleep(1)
  23. numberGuess(0, 100)
  24. #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