Moortiii

Number Guessing Game

Mar 29th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. import random
  2. import sys
  3.  
  4. def playAgain():
  5.     choice = raw_input("\nDo you want to play again? 'Y' / 'N': \n")
  6.     if(choice == "Y"):
  7.         playGame()
  8.     else:
  9.         sys.exit()
  10.  
  11. def playGame():
  12.     number = random.randint(1, 100)
  13.     guesses = 4
  14.     while(guesses > 0):
  15.         guess = int(raw_input("\nGuess a whole number between 1 and 100: "))
  16.         if(guess == number):
  17.             print("\nYou guessed correctly!")
  18.             guesses = -1
  19.         elif(guess < number):
  20.             print("Your guess was too low. " + str(guesses) + " tries left. Guess again: \n")
  21.             guesses -= 1
  22.         elif(guess > number):
  23.             print("Your guess was too high " + str(guesses) + " tries left. Guess again: \n")
  24.             guesses -= 1
  25.  
  26. playGame()
  27. playAgain()
Advertisement
Add Comment
Please, Sign In to add comment