Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create an Operator Game
- # The randint function
- import random
- secret = random.randint(1,20)
- print(secret)
- # Declaring the variables
- guess = 0
- tries = 0
- # Starting the game
- print('Try to guess a number between 1 and 20, using the four clues if you need them, You have 5 guesses')
- # Setting up the while loop
- while (guess!=secret) and (tries<5):
- guess = int(input ('What is your guess? ')) # use the int function to convert the user’s guess into an integer
- tries = tries + 1
- if guess == secret:
- print('You got it')
- elif tries == 1 and guess < secret:
- print('Your first clue is that your guess is too low, try again')
- elif tries == 1 and guess > secret:
- print('Your first clue is that your guess is too high, try again')
- elif tries == 2 and (secret/2)<7:
- print('No, sorry, your second clue is that the secret number divided by 2 is less than 7')
- elif tries == 2 and (secret/2)>=7:
- print('No, sorry, your second clue is that the secret number divided by 2 is greater than or equal to 7')
- elif tries ==3:
- print('No, sorry, your third clue is that the floor (integer) division of the secret number by 3 is', secret//3)
- elif tries == 4:
- print('No, sorry, your fourth clue is that the modulus of the secret number divided by 3 is', secret%3)
- if guess!=secret:
- print ('Wrong, sorry, you have used up your five guesses. Better luck next time.')
- print ('The secret number was',secret)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement