{{ message }}

Instantly share code, notes, and snippets.

# akinjide/guess.py

Last active May 5, 2017
A simple Guess The Number game implementation in Python.
 from random import randrange class Guess: def play(self): print "The computer will select a secret number between 1 and 10." print "Try to find the secret number using a minimum number of guesses." play, secret, guess, guesses, answer = True, 0, 0, 0, None while play: secret = randrange(1, 10) while guess != secret: guess = int(raw_input("Your guess: ")) if guess < secret: print "The secret number is greater than %s. Guess again!" % (guess) elif guess > secret: print "The secret number is less than %s. Guess again!" % (guess) guesses += 1 print "Congratulations :)" print "You found the secret number (%s) in %s guess(es)." % (secret, guesses) while answer != "yes" and answer != "no": answer = raw_input("Play again? (yes or no): ").lower() if answer == "no": play = False print "Thank you for playing :)" guess = Guess() guess.play()