SHARE
TWEET

Untitled

Tom_Jung Apr 24th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Future Learn  / Logic & Maths / Guessing Game
  2.  
  3. import random
  4. secret = random.randint(1,50)
  5. #print("Secret number is ", secret)
  6.  
  7. guess = 0
  8. tries = 0
  9.  
  10. print("Guess a number between 1 and 50 in five tries.")
  11.  
  12. while (guess!=secret) and (tries<5):
  13.  
  14.     guess = int(input("Enter your guess:  "))
  15.  
  16.     tries = tries + 1
  17.     print("Tries = ", tries)
  18.  
  19.     if guess == secret:
  20.         print("Yeah, you got it!")
  21.     elif guess < secret:
  22.         print("Your guess it too low")
  23.     elif guess > secret:
  24.         print("your guess is too high")
  25.        
  26. if tries==5 and guess!=secret:
  27.     print("You are out of tries")
  28.     print("You did not guess the secret number")
  29.     print("The secret number is ", secret)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top