Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is a guess the number game.
- import random
- replay = 1
- print('Hello! What is your name?')
- myName = input()
- while replay:
- guessesTaken = 0
- number = random.randint(1, 30)
- print('Well, ' + myName + ', I am thinking of a number between 1 and 30.')
- while guessesTaken < 4:
- print('Take a guess.') # There are four spaces in front of print.
- guess = input()
- guess = int(guess)
- guessesTaken = guessesTaken + 1
- if guess < number:
- print('Your guess is too low.') # There are eight spaces in front of print.
- elif guess > number:
- print('Your guess is too high.')
- elif guess == number:
- break
- if guess == number:
- guessesTaken = str(guessesTaken)
- print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
- elif guess != number:
- number = str(number)
- print('Nope. The number I was thinking of was ' + number)
- replayInput = input("Would you like to play again? (y/n)");
- if replayInput == "y":
- replay = 1
- else:
- replay = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement