amninder

7 Guesses Game using Python

Feb 9th, 2018
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. # 7 GUESSES GAME - PYTHON
  2. #IN 7 GUESSES AT MAX. YOU HAVE TO GUESS MY SECRET NUMBER.
  3. import random
  4.  
  5. print('Hi there, What\'s your name?')
  6. name = input()
  7.  
  8. print('Hey ' + str(name) + ', I have a number between 1 to 10, Can you guess it?!')
  9. secretNumber = random.randint(1,10)
  10.  
  11. #giving 7 chances to user using for loop
  12. for guessesdone in range(1,8):
  13. print('Take a guess')
  14. guess = int(input())
  15.  
  16. try:
  17. #guess conditions
  18. if guess < secretNumber:
  19. print('Guess is close but little low,Try again!')
  20. elif guess > secretNumber:
  21. print('Guess is close but little high. Try again!')
  22. else:
  23. break # This happens when guess is equal to secretNumber.
  24.  
  25. except ValueError:
  26. print('Come on! I was expecting a number man :(')
  27.  
  28. if guess == secretNumber:
  29. print('Hey ' + str(name) + ',You guessed right! in your '+ str(guessesdone) +' chances!')
  30. else:
  31. print('My secret number was:'+str(secretNumber) + '.Well, it\'s okay, you can play again!')
Add Comment
Please, Sign In to add comment