brilliant_moves

YahooHangman.py

Nov 30th, 2014
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. #!/usr/bin/python
  2. #Python2.7
  3.  
  4. import random
  5.  
  6. HANGMAN = ['''
  7. +---+
  8. | |
  9. |
  10. |
  11. |
  12. |
  13. =========''', '''
  14. +---+
  15. | |
  16. O |
  17. |
  18. |
  19. |
  20. =========''', '''
  21. +---+
  22. | |
  23. O |
  24. | |
  25. |
  26. |
  27. =========''', '''
  28. +---+
  29. | |
  30. O |
  31. /| |
  32. |
  33. |
  34. =========''', '''
  35. +---+
  36. | |
  37. O |
  38. /|\ |
  39. |
  40. |
  41. =========''', '''
  42. +---+
  43. | |
  44. O |
  45. /|\ |
  46. / |
  47. |
  48. =========''', '''
  49. +---+
  50. | |
  51. O |
  52. /|\ |
  53. / \ |
  54. |
  55. =========''']
  56.  
  57. Max_Wrong= len(HANGMAN)-1
  58. words = 'ant baboon badger coyote chipmonk'.split()
  59. Word=random.choice(words)
  60. so_far= '_' * len(Word)
  61. wrong=0
  62. used=[]
  63.  
  64. print "Welcome to Hangman, Good Luck"
  65.  
  66. while wrong < Max_Wrong and so_far != Word:
  67.     print HANGMAN[wrong]
  68.     print "\nYou have used the following letters:", used
  69.     print "\nSo far, the word is:", so_far
  70.     guess=raw_input("Guess a single letter: ")
  71.     guess=guess.lower()
  72.  
  73.     while guess in used:
  74.         print "You have already guessed the letter:", guess
  75.         guess=raw_input("Guess a single letter: ")
  76.         guess=guess.lower()
  77.     used.append(guess)
  78.  
  79.     if guess in Word:
  80.         print "\nYes,", guess, "is in the word"
  81.  
  82.         for i in range(len(Word)):
  83.             if guess==Word[i]:
  84.                 so_far= so_far[:i]+ Word[i]+ so_far[i+1:]
  85.                
  86.         print so_far
  87.     else:
  88.         print "\nSorry,", guess, "isn't in the word"
  89.         wrong+=1
  90.        
  91. if wrong==Max_Wrong:
  92.     print HANGMAN[wrong]
  93.     print "\nYou have been hanged"
  94. else:
  95.     print "\nYou guessed it"
  96.     print "\nThe word was", Word
  97. input("Press enter key to exit")
Add Comment
Please, Sign In to add comment