Created
June 12, 2013 15:46
-
-
Save imjacobclark/5766534 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# We'll need some random functionality in this game :-) | |
import random | |
# The list of words we want the computer to choose from | |
alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','r','v','w','x','y','z'] | |
words = ['computer', 'science', 'computing', 'school', 'alan', 'turing', 'microsoft', 'macintosh'] | |
rightGuessedLetters = [] | |
wrongGuessedLetters = [] | |
# ------------------------------ FUNCTIONS ---------------------------------------------------------- | |
# An instruction that tells the computer to get a random word from the word list | |
def getWord(): | |
return random.randint(0, len(words) - 1) | |
# An instruction to tell the computer to ask the player for their guess | |
def getGuess(): | |
return raw_input("Please enter a guess (just one letter)... ") | |
# ------------------------------ END FUNCTIONS ------------------------------------------------------ | |
word = getWord() | |
print "\n #define 2013 - H A N G M A N! \n" | |
print "Your word to guess is " + str(len(words[word])) + " letters long." | |
while True: | |
# Run the function that asks the player for a guess | |
guess = getGuess() | |
# If the guess was in our randomly chosen word, yay! | |
if(guess in words[word]): | |
rightGuessedLetters.append(guess) | |
# If the guess wasn't in our randomly chosen word, damn! | |
else: | |
wrongGuessedLetters.append(guess) | |
# The player has 7 lives, if they guess incorrectly 7 times, they're dead! | |
if(len(wrongGuessedLetters) == 7): | |
print "Dead!" | |
print "The word was... " + words[word] | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment