Created
September 10, 2012 02:58
-
-
Save axsuul/3688585 to your computer and use it in GitHub Desktop.
hangman
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
#Hangman | |
import random | |
words = ["apple", "banana", "pen", "cat", "dog", "bee", "pig"] | |
print "Welcome to the Hangman game. You will have six chances to guss my secret word correctly. Good luck!" | |
word = words[random.randint(0,len(words)-1)] | |
def dash(word): | |
list = [] | |
for i in word: | |
list.append("_") | |
return list | |
outcome = dash(word) | |
print " ".join(outcome).strip() | |
def match(letter): | |
word_list = list(word) | |
for i, j in enumerate(word_list): | |
if j == letter: | |
outcome[i] = j | |
return outcome | |
games_left = 6 | |
while true: | |
if games_left == 0: | |
print "Loser. The answer was " + word | |
break | |
print "You have " + str(games_left) + " guesses left." | |
letter = raw_input("Your guess (letters only): ") | |
outcome = match(letter) | |
print " ".join(outcome).strip() | |
if outcome == list(word): | |
print "Great Job!" | |
break | |
games_left -= 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment