SHARE
TWEET

Guessing game

a guest Mar 20th, 2017 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3. print("What is your name?")
  4. name = input()
  5. print("Well,", name + ".  I'm thinking of a number between 1 and 20.")
  6.  
  7. # ask to guess 6 times.
  8.  
  9. def guessGame():
  10.     secretNumber = random.randint(1,20)
  11.     attempts = 0
  12.     guessed = False
  13.  
  14.     while attempts <= 6:
  15.         print("Take a guess..")
  16.         guess = int(input())
  17.  
  18.         if guess < secretNumber:
  19.             print("Your guess is too low.")
  20.  
  21.         elif guess > secretNumber:
  22.             print("Your guess is too high")
  23.         elif guess == secretNumber:
  24.             print("Great job!")
  25.             attempts = 7
  26.             guessed = True
  27.  
  28.  
  29.         attempts += 1
  30.  
  31.     if guessed == False and attempts == 7:
  32.         print("Nope.  The number I was thinking of was", secretNumber)
  33.  
  34.     print("Would you like to play again?")
  35.  
  36.     response = input()
  37.  
  38.     if response.lower() in ["yes", "yeah", "yep", "affirmative"]:
  39.         guessGame()
  40.     elif response.lower() in ["no", "nope", "piss off"]:
  41.         print("Goodbye")
  42.  
  43.  
  44. guessGame()
RAW Paste Data
Top