#! /usr/bin/env python import random words = ['yxa', 'shipoopi', 'tux', 'nemrod', 'dreamhack', 'python'] word = random.choice(words) right = wrong = [] while True: # print the current scenery file = open('ascii', 'r') hangman = file.readlines() print ''.join([line for line in hangman[len(wrong) * 10:len(wrong) * 10 + 10]]) # print the word with correctly guessed letters else underscore for letter in word: print letter if letter in right else '_ ', print '' # print wrong guesses print 'Wrong: ' + ' '.join([letter for letter in wrong]) # check if we've won if len([letter for letter in word if letter not in right]) == 0: print 'You found the word! Congratulations!' break # check if we've lost if len(wrong) == len(hangman) / 10 - 1: print 'You got hung!' break # get the guess letter = raw_input('Enter letter: ') if len(letter) > 1: print 'You may only try one letter at a time!' elif letter in right + wrong: print 'You\'ve already tried that letter!' else: # valid guess, now let's see if it's right or wrong if letter in word: print '\'' + letter + '\' was in the word!' right += letter else: print '\'' + letter + '\' was not in the word.' wrong += letter print ''