Advertisement
Guest User

michael_siever_Lab6b_update2

a guest
Nov 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import random
  2.  
  3. random_number = random.randint (1, 100)
  4. count = 0
  5.  
  6. def guessing_game():
  7. print("Let's play a number guessing game!")
  8. guess = int(input('Guess a number between 1 and 100: ')
  9. if guess > random_number:
  10. print('Too high! Guess again!')
  11. count = count + 1
  12. elif guess < random_number:
  13. print('Too low! Guess again!')
  14. count = count + 1
  15. else:
  16. print('You guessed the correct number in', count, 'attempts!')
  17. while guess != random_number
  18. return guess
  19.  
  20. def main():
  21. keep_playing == "y"
  22. while keep_playing == "y":
  23. guessing_game()
  24. keep_playing = input('Would you like to play again? Press "y" to play again or any other key to exit: ')
  25.  
  26. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement