Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!

# Simple Python number guessing game

By: a guest on Jul 21st, 2011  |  syntax: Python  |  size: 1.40 KB  |  views: 142  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
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.
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
clone this paste RAW Paste Data
Top