Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #Python2.7
- import random
- HANGMAN = ['''
- +---+
- | |
- |
- |
- |
- |
- =========''', '''
- +---+
- | |
- O |
- |
- |
- |
- =========''', '''
- +---+
- | |
- O |
- | |
- |
- |
- =========''', '''
- +---+
- | |
- O |
- /| |
- |
- |
- =========''', '''
- +---+
- | |
- O |
- /|\ |
- |
- |
- =========''', '''
- +---+
- | |
- O |
- /|\ |
- / |
- |
- =========''', '''
- +---+
- | |
- O |
- /|\ |
- / \ |
- |
- =========''']
- Max_Wrong= len(HANGMAN)-1
- words = 'ant baboon badger coyote chipmonk'.split()
- Word=random.choice(words)
- so_far= '_' * len(Word)
- wrong=0
- used=[]
- print "Welcome to Hangman, Good Luck"
- while wrong < Max_Wrong and so_far != Word:
- print HANGMAN[wrong]
- print "\nYou have used the following letters:", used
- print "\nSo far, the word is:", so_far
- guess=raw_input("Guess a single letter: ")
- guess=guess.lower()
- while guess in used:
- print "You have already guessed the letter:", guess
- guess=raw_input("Guess a single letter: ")
- guess=guess.lower()
- used.append(guess)
- if guess in Word:
- print "\nYes,", guess, "is in the word"
- for i in range(len(Word)):
- if guess==Word[i]:
- so_far= so_far[:i]+ Word[i]+ so_far[i+1:]
- print so_far
- else:
- print "\nSorry,", guess, "isn't in the word"
- wrong+=1
- if wrong==Max_Wrong:
- print HANGMAN[wrong]
- print "\nYou have been hanged"
- else:
- print "\nYou guessed it"
- print "\nThe word was", Word
- input("Press enter key to exit")
Add Comment
Please, Sign In to add comment