Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import random
  2. # Your goal for tonight is to create a number guessing game. Your program will pick a random number between 1 and 100 and repeatedly ask you for guesses.
  3. def get_guess():
  4. return int(input("5 tries to guess a number between 1 & 100: "))
  5. #how would i get it to countdown the number of guesses left?
  6.  
  7. def rand_num_creator():
  8. return random.randrange(1, 100)
  9.  
  10. rand_num = rand_num_creator()
  11. count = 5
  12. user_guess_list = []
  13.  
  14. while count > 0:
  15.  
  16. user_guess = get_guess()
  17.  
  18. if user_guess in user_guess_list:
  19. print("guess a number once not twice")
  20. continue
  21.  
  22. user_guess_list.append(user_guess)
  23.  
  24. if user_guess == rand_num:
  25. print("you won and it took you {} guesses".format(len(user_guess_list)))
  26. break
  27. elif count == 1:
  28. print("ran out of guesses")
  29. break
  30. elif user_guess < rand_num:
  31. print("too low")
  32. count -= 1
  33. elif user_guess > rand_num:
  34. print("too high")
  35. count -= 1
  36.  
  37. print("Thanks for playing!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement