Skip to content

Instantly share code, notes, and snippets.

@axsuul
Created September 10, 2012 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axsuul/3688585 to your computer and use it in GitHub Desktop.
Save axsuul/3688585 to your computer and use it in GitHub Desktop.
hangman
#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