Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- print("What is your name?")
- name = input()
- print("Well,", name + ". I'm thinking of a number between 1 and 20.")
- # ask to guess 6 times.
- def guessGame():
- secretNumber = random.randint(1,20)
- attempts = 0
- guessed = False
- while attempts <= 6:
- print("Take a guess..")
- guess = int(input())
- if guess < secretNumber:
- print("Your guess is too low.")
- elif guess > secretNumber:
- print("Your guess is too high")
- elif guess == secretNumber:
- print("Great job!")
- attempts = 7
- guessed = True
- attempts += 1
- if guessed == False and attempts == 7:
- print("Nope. The number I was thinking of was", secretNumber)
- print("Would you like to play again?")
- response = input()
- if response.lower() in ["yes", "yeah", "yep", "affirmative"]:
- guessGame()
- elif response.lower() in ["no", "nope", "piss off"]:
- print("Goodbye")
- guessGame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement