Skip to content

Instantly share code, notes, and snippets.

@jamie23
Created April 28, 2015 00:34
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 jamie23/c866a719b39d89581ed8 to your computer and use it in GitHub Desktop.
Save jamie23/c866a719b39d89581ed8 to your computer and use it in GitHub Desktop.
Very quick hangman game to teach primary school kids in 1 hour
Making a hangman game, woohoo
#Get input and convert to list
word = raw_input("Please input your word: ");
word = list(word);
guesses = 5;
#Setting up our hashes list
guessingWord = len(word)*["*"];
while(guesses>0):
guessLetter = raw_input("Please enter a char to guess: ");
for i in range(0,len(word)):
if(word[i]==guessLetter):
guessingWord[i]=guessLetter;
if not "*" in guessingWord:
break;
print ''.join(guessingWord);
guesses = guesses-1;
#Output as a string
if guesses>0:
print("You have won the game!!!");
else:
print("Sorry but you ran out of guesses, the correct answer was: ");
print ''.join(word);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment