crzcas

operator game

Dec 28th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. # Operator game
  2.  
  3. import random
  4. secret = random.randint(1,20)  # Return a random integer N such that a <= N <= b. Alias for randrange(a, b+1).
  5. guess = 0
  6. tries = 0
  7.  
  8. print('Try to guess a number between 1 and 20, using the four clues if you need them.')
  9. print('You have 5 guesses.')
  10.  
  11. while (guess != secret) and (tries < 5):   # Attempts 0, 1, 2, 3, 4 and in total are 5
  12.     guess = int(input('What is your guess? '))
  13.     tries = tries + 1
  14.  
  15. if guess == secret:
  16.     print('You got it')
  17.        
  18. if guess != secret:
  19.     print ('Wrong, sorry, you have used up your five guesses. Better luck next time.')
  20.     print ('The secret number was', secret)    
Advertisement
Add Comment
Please, Sign In to add comment