Advertisement
Guest User

Operator Game

a guest
Apr 4th, 2020
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. # Create an Operator Game
  2.  
  3. # The randint function
  4. import random
  5. secret = random.randint(1,20)
  6. print(secret)
  7.  
  8. # Declaring the variables
  9. guess = 0
  10. tries = 0
  11.  
  12. # Starting the game
  13. print('Try to guess a number between 1 and 20, using the four clues if you need them, You have 5 guesses')
  14.  
  15. # Setting up the while loop
  16. while (guess!=secret) and (tries<5):
  17.     guess = int(input ('What is your guess? ')) # use the int function to convert the user’s guess into an integer
  18.     tries = tries + 1
  19.     if guess == secret:
  20.         print('You got it')
  21.     elif tries == 1 and guess < secret:
  22.         print('Your first clue is that your guess is too low, try again')
  23.     elif tries == 1 and guess > secret:
  24.         print('Your first clue is that your guess is too high, try again')
  25.     elif tries == 2 and (secret/2)<7:
  26.         print('No, sorry, your second clue is that the secret number divided by 2 is less than 7')
  27.     elif tries == 2 and (secret/2)>=7:
  28.          print('No, sorry, your second clue is that the secret number divided by 2 is greater than or equal to 7')
  29.     elif tries ==3:
  30.         print('No, sorry, your third clue is that the floor (integer) division of the secret number by 3 is', secret//3)
  31.     elif tries == 4:
  32.          print('No, sorry, your fourth clue is that the modulus of the secret number divided by 3 is', secret%3)
  33.  
  34. if guess!=secret:
  35.     print ('Wrong, sorry, you have used up your five guesses. Better luck next time.')
  36.     print ('The secret number was',secret)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement