Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 7 GUESSES GAME - PYTHON
- #IN 7 GUESSES AT MAX. YOU HAVE TO GUESS MY SECRET NUMBER.
- import random
- print('Hi there, What\'s your name?')
- name = input()
- print('Hey ' + str(name) + ', I have a number between 1 to 10, Can you guess it?!')
- secretNumber = random.randint(1,10)
- #giving 7 chances to user using for loop
- for guessesdone in range(1,8):
- print('Take a guess')
- guess = int(input())
- try:
- #guess conditions
- if guess < secretNumber:
- print('Guess is close but little low,Try again!')
- elif guess > secretNumber:
- print('Guess is close but little high. Try again!')
- else:
- break # This happens when guess is equal to secretNumber.
- except ValueError:
- print('Come on! I was expecting a number man :(')
- if guess == secretNumber:
- print('Hey ' + str(name) + ',You guessed right! in your '+ str(guessesdone) +' chances!')
- else:
- print('My secret number was:'+str(secretNumber) + '.Well, it\'s okay, you can play again!')
Add Comment
Please, Sign In to add comment