Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Alphabet = "abcdefghijklmnopqrstuvwxyz"
- HANGMAN = (
- """
- ------
- | |
- |
- |
- |
- |
- |
- |
- |
- ----------
- """,
- """
- ------
- | |
- | O
- |
- |
- |
- |
- |
- |
- ----------
- """,
- """
- ------
- | |
- | O
- | -+-
- |
- |
- |
- |
- |
- ----------
- """,
- """
- ------
- | |
- | O
- | /-+-
- |
- |
- |
- |
- |
- ----------
- """,
- """
- ------
- | |
- | O
- | /-+-/
- |
- |
- |
- |
- |
- ----------
- """,
- """
- ------
- | |
- | O
- | /-+-/
- | |
- |
- |
- |
- |
- ----------
- """,
- """
- ------
- | |
- | O
- | /-+-/
- | |
- | |
- | | |
- |
- |
- ----------
- """,
- """
- ------
- | |
- | O
- | /-+-/
- | |
- | |
- | | |
- | | |
- |
- ----------
- """)
- #Initialize the guess count
- guessCount = 1
- #Get the word
- word = raw_input ("Enter the word: ")
- #Get the length of the word
- wordLength = len(word)
- #Initialize the blanks
- blanks = ""
- #For each letter, add one "_ " to blanks
- for i in range (wordLength):
- blanks = blanks + "_ "
- blanksLength = len(blanks)
- #Show to user
- print (blanks)
- #Initialize a list of guessed letters
- letterGuessList = ""
- #Initialize the wrong count
- wrongCount = 0
- # += means plus equals. It reads like letterGuessList = letterGuessList + other stuff
- letterGuessList += raw_input ("Guess a letter: ")
- #If the count is greater than 7, don't show them again
- while (guessCount < 7):
- #Get their letter guess
- letterGuess = letterGuessList[len(letterGuessList)-1]
- if letterGuess not in Alphabet:
- print("You freakin' idiot, you already used that letter")
- letterGuessList+= raw_input("Guess a letter: ")
- else:
- #Set the blanks to nothing
- blanks = ""
- #Show the # of guesses left
- print ("You have " + str(7-guessCount)+ " guesses remaining.")
- #For each letter in the secret word, do the following
- for letterAns in word:
- #If that secret letter is in the guess list, they have it right
- if letterAns in letterGuessList:
- #We add that letter to the "blanks" string
- blanks += letterAns
- #Otherwise, if the secret letter ISN'T in the guess list, do the following
- else:
- #Add an underscore the "blanks" string
- blanks += "_ "
- #Increase their wrong count
- if letterGuess not in word:
- wrongCount +=1
- #Print by index
- print HANGMAN[wrongCount]
- #Show the blanks after each loop
- print(blanks)
- #Letters remaning
- Alphabet = Alphabet.replace(letterGuess, "")
- print("Letters remaining: " + Alphabet)
- #Make them guess a letter again
- guessCount +=1
- if "_" not in blanks:
- break
- letterGuessList+= raw_input("Guess a letter: ")
- if "_" in blanks:
- print("Sorry, you lost!")
- else:
- print("Yay! You win!")
Add Comment
Please, Sign In to add comment