scipiguy

Logical Expressions and Python-Comparison number guess game

Oct 28th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. # Futurelearn maths and logic course game
  2.  
  3. from random import randint
  4.  
  5. secret = randint(1,20)
  6.  
  7. guess = 0
  8. tries = 0
  9.  
  10. print(str(secret) + "Try to guess a number between 1 and 20, using the four clues if you need them. You have 5 guesses.")
  11.  
  12. while (guess != secret) and (tries < 5):
  13.     guess = int(input("What is your guess? "))
  14.     tries += 1
  15.     if guess == secret:
  16.         print("You got it!")
  17.     elif tries == 1:
  18.         print("This is your first clue. Your guess was ", end = '')
  19.         if guess < secret:
  20.             print("too low.")
  21.         else:
  22.             print("too high.")
  23.     elif tries == 2:
  24.         print("This is your second clue. The number you are trying to guess is ", end = '')
  25.         if secret%2 == 0:
  26.             print("divisable by 2.")
  27.         else:
  28.             print("not divisable by 2.")
  29.     elif tries == 3:
  30.         print("No, sorry, your third clue is that the modulus of the secret number divided by 3 is " + str(secret%3) + ".")
  31.     elif tries == 4:
  32.         print("Down to your last guess. The answer to '20//5' is ", end = '')
  33.         if 20//5 > secret:
  34.             print("greater than the secret number.")
  35.         else:
  36.             print("less than the secret number.")
  37.     else:
  38.         print("Game over.")
  39. if guess != secret:
  40.     print("\nWrong, sorry, you have used up your five guesses. Better luck next time.")
  41.     print("\nThe secret number was " + str(secret) + ".")
Advertisement
Add Comment
Please, Sign In to add comment