Last active
August 29, 2015 14:23
-
-
Save jonathanpike/8dfbcb971b96873166bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from http://www.practicepython.org/exercise/2014/04/02/09-guessing-game-one.html | |
import random | |
def chkguess(): | |
stop = "go" | |
guessnum = 0 | |
while stop == "go": | |
guess = int(raw_input("Choose a number between 1 and 9: ")) | |
number = random.randint(1,9) | |
if guess == number: | |
guessnum += 1 | |
print "You guessed correctly!" | |
stop = raw_input("Type 'go' to play again or 'exit' to stop game.") | |
elif guess > number and guess <= 9: | |
guessnum += 1 | |
print "Too high!" | |
print "The number was %d" % number | |
print "This is so fun, let's keep playing!" | |
stop = raw_input("Type 'go' to play again or 'exit' to stop game.") | |
elif guess < number: | |
guessnum += 1 | |
print "Too low!" | |
print "The number was %d" % number | |
print "This is so fun, let's keep playing!" | |
stop = raw_input("Type 'go' to play again or 'exit' to stop game.") | |
else: | |
print "That number isn't between 1 and 9. Guess again." | |
print "You guessed %d times!" % guessnum | |
chkguess() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment