Guest User

Untitled

a guest
Jun 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1. Alphabet = "abcdefghijklmnopqrstuvwxyz"
  2. HANGMAN = (
  3. """
  4. ------
  5. |    |
  6. |
  7. |
  8. |
  9. |
  10. |
  11. |
  12. |
  13. ----------
  14. """,
  15. """
  16. ------
  17. |    |
  18. |    O
  19. |
  20. |
  21. |
  22. |
  23. |
  24. |
  25. ----------
  26. """,
  27. """
  28. ------
  29. |    |
  30. |    O
  31. |   -+-
  32. |
  33. |  
  34. |  
  35. |  
  36. |  
  37. ----------
  38. """,
  39. """
  40. ------
  41. |    |
  42. |    O
  43. |  /-+-
  44. |  
  45. |  
  46. |  
  47. |  
  48. |  
  49. ----------
  50. """,
  51. """
  52. ------
  53. |    |
  54. |    O
  55. |  /-+-/
  56. |  
  57. |  
  58. |  
  59. |  
  60. |  
  61. ----------
  62. """,
  63. """
  64. ------
  65. |    |
  66. |    O
  67. |  /-+-/
  68. |    |
  69. |  
  70. |  
  71. |  
  72. |  
  73. ----------
  74. """,
  75. """
  76. ------
  77. |    |
  78. |    O
  79. |  /-+-/
  80. |    |
  81. |    |
  82. |   | |
  83. |
  84. |  
  85. ----------
  86. """,
  87. """
  88. ------
  89. |    |
  90. |    O
  91. |  /-+-/
  92. |    |
  93. |    |
  94. |   | |
  95. |   | |
  96. |  
  97. ----------
  98. """)
  99.  
  100. #Initialize the guess count
  101. guessCount = 1
  102.  
  103. #Get the word
  104. word = raw_input ("Enter the word: ")
  105.  
  106. #Get the length of the word
  107. wordLength = len(word)
  108.  
  109. #Initialize the blanks
  110. blanks = ""
  111.  
  112. #For each letter, add one "_ " to blanks
  113. for i in range (wordLength):
  114.     blanks = blanks + "_ "
  115.     blanksLength = len(blanks)
  116.    
  117. #Show to user
  118. print (blanks)
  119.  
  120. #Initialize a list of guessed letters
  121. letterGuessList = ""  
  122.  
  123. #Initialize the wrong count
  124. wrongCount = 0
  125.  
  126. # += means plus equals. It reads like letterGuessList = letterGuessList + other stuff
  127. letterGuessList += raw_input ("Guess a letter: ")
  128.  
  129. #If the count is greater than 7, don't show them again
  130. while (guessCount < 7):
  131.    
  132.     #Get their letter guess
  133.     letterGuess = letterGuessList[len(letterGuessList)-1]
  134.  
  135.     if letterGuess not in Alphabet:
  136.             print("You freakin' idiot, you already used that letter")
  137.             letterGuessList+= raw_input("Guess a letter: ")
  138.     else:  
  139.         #Set the blanks to nothing
  140.         blanks = ""
  141.        
  142.         #Show the # of guesses left
  143.         print ("You have " +  str(7-guessCount)+ " guesses remaining.")
  144.        
  145.         #For each letter in the secret word, do the following
  146.         for letterAns in word:
  147.            
  148.             #If that secret letter is in the guess list, they have it right
  149.             if letterAns in letterGuessList:
  150.                
  151.                 #We add that letter to the "blanks" string
  152.                 blanks += letterAns
  153.                
  154.             #Otherwise, if the secret letter ISN'T in the guess list, do the following
  155.             else:
  156.                
  157.                 #Add an underscore the "blanks" string
  158.                 blanks += "_ "
  159.                
  160.                
  161.         #Increase their wrong count
  162.         if letterGuess not in word:
  163.             wrongCount +=1
  164.        
  165.         #Print by index
  166.         print HANGMAN[wrongCount]
  167.        
  168.         #Show the blanks after each loop
  169.         print(blanks)
  170.        
  171.         #Letters remaning
  172.         Alphabet = Alphabet.replace(letterGuess, "")
  173.         print("Letters remaining: " + Alphabet)
  174.        
  175.         #Make them guess a letter again
  176.         guessCount +=1
  177.         if "_" not in blanks:
  178.             break
  179.         letterGuessList+= raw_input("Guess a letter: ")
  180.    
  181. if "_" in blanks:
  182.     print("Sorry, you lost!")
  183. else:
  184.     print("Yay! You win!")
Add Comment
Please, Sign In to add comment