SHARE
TWEET

Simple Python number guessing game

a guest Jul 21st, 2011 142 Never
  1. #!/usr/bin/python
  2.  
  3. import random
  4. '''
  5. Random number guessing game. Just made because I was bored. :p
  6. Number is randomly generated from between 1 and 100.
  7. Made by nu11byte.
  8. A lot of un-needed crap, but I was just having a play. Just refreshing
  9. my mind. Parts of Python have been forgot and left behind for other languages syntax. Luckily Python's
  10. syntax is quite similar to other languages.
  11. '''
  12.  
  13. #Use and edit this as you wish.
  14. def cls():
  15.         print '''
  16.        
  17. ______            _                
  18. (_____ \     _   | |                
  19. _____) )   _| |_ | | _   ___  ____  
  20. |  ____/ | | |  _)| || \ / _ \|  _ \
  21. | |    | |_| | |__| | | | |_| | | | |
  22. |_|     \__  |\___)_| |_|\___/|_| |_|
  23.       (____/                        
  24.        
  25.         '''
  26.         print "\n"
  27. cls()
  28. print "Guess what number I am thinking of. My number is between 1 and 100."
  29.  
  30. def main():
  31.         randomNumber = random.randint(1,100)
  32.         userGuess = 0
  33.         guessCount = 0
  34.         while (userGuess!=randomNumber):
  35.                 userGuess = int(input("Guess: "))
  36.                 guessCount += 1
  37.                 if (userGuess < randomNumber):
  38.                         print "Guess a little higher."
  39.                 elif (userGuess > randomNumber):
  40.                         print "Guess a little lower."
  41.                 else:
  42.                         print "It took you %d goes to correctly guess the number." % guessCount
  43.                         pause = raw_input("Play again? (y/n): ");
  44.                         if (pause == "y"):
  45.                                 userGuess = 0
  46.                                 guessCount = 0
  47.                                 randomNumber = random.randint(1,100)
  48.                                 cls()
  49.                                
  50. main()
  51. ###EOF
RAW Paste Data
Top