Advertisement
Guest User

michael_siever_Lab6b_update3

a guest
Nov 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. # Create import of random number
  2. import random
  3.  
  4. # Define function for a guessing game
  5. def guessing_game():
  6. again = 'y'
  7. while again != 'n':
  8. random_num = random.randint (1, 100)
  9. print("Let's play a number guessing game!")
  10. guess = int(input('\nGuess a number between 1 and 100: '))
  11. guess_count = int(0)#this too
  12. repeat = True #Inital start
  13. while repeat != False: #control loop for guesses
  14. if guess > random_num:
  15. guess = int(input('\nToo high! Guess again!: '))
  16. elif guess < random_num:
  17. guess = int(input('\nToo low! Guess again!: '))
  18. else:
  19. repeat = False #if player guesses correctly, it will proceed
  20. guess_count +=1
  21. if guess_count == 1:
  22. print('Congratulations! You guessed the correct number in', guess_count, 'attempt!')
  23. else:
  24. print('You guessed the correct number in', guess_count, 'attempts!')
  25. # Prompt user to play again or quit
  26. keep_playing = str(input('Would you like to play again?\n' \
  27. '(Yes/No): ').lower())
  28. if keep_playing != 'Yes':
  29. again = False
  30. print('Thanks for playing! Goodbye!')
  31. guessing_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement