Advertisement
electricmaster

Untitled

Sep 2nd, 2016
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1.  # This is a guess the number game.
  2. import random
  3.  
  4. replay = 1
  5.  
  6. print('Hello! What is your name?')
  7. myName = input()
  8.  
  9. while replay:
  10.     guessesTaken = 0
  11.     number = random.randint(1, 30)
  12.  
  13.     print('Well, ' + myName + ', I am thinking of a number between 1 and 30.')
  14.  
  15.     while guessesTaken < 4:
  16.         print('Take a guess.') # There are four spaces in front of print.
  17.         guess = input()
  18.         guess = int(guess)
  19.  
  20.         guessesTaken = guessesTaken + 1
  21.  
  22.         if guess < number:
  23.             print('Your guess is too low.') # There are eight spaces in front of print.
  24.  
  25.         elif guess > number:
  26.             print('Your guess is too high.')
  27.  
  28.         elif guess == number:
  29.             break
  30.  
  31.     if guess == number:
  32.  
  33.         guessesTaken = str(guessesTaken)
  34.         print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
  35.  
  36.     elif guess != number:
  37.         number = str(number)
  38.         print('Nope. The number I was thinking of was ' + number)
  39.  
  40.     replayInput = input("Would you like to play again? (y/n)");
  41.     if replayInput == "y":
  42.         replay = 1
  43.     else:
  44.         replay = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement