Created
September 10, 2012 02:35
-
-
Save axsuul/3688498 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 str_spliter(word): | |
list = [] | |
for i in word: | |
list.append(i + " ") | |
return list | |
print "".join(str_spliter(word)).strip() | |
print str_spliter(word) | |
def match(letter): | |
word_list = str_spliter(word) | |
for i, j in enumerate(word_list): | |
if j == letter + " ": | |
outcome[i] = j | |
return outcome | |
games_left = 6 | |
while games_left > 0: | |
print outcome | |
if outcome == str_spliter(word): | |
print "Great Job!" | |
break | |
else: | |
print "You have " + str(games_left) + " guesses left." | |
letter = raw_input("Your guess (letters only): ") | |
outcome = match(letter) | |
print "".join(outcome).strip() | |
games_left -= 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment