Advertisement
Guest User

Hangman

a guest
Jan 19th, 2022
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. import random
  2. import hangman_words
  3. import hangman_art
  4. from replit import clear
  5.  
  6. stages = ['''
  7.  +---+
  8.  |   |
  9.  O   |
  10. /|\ |
  11. / \ |
  12.      |
  13. =========
  14. ''', '''
  15.  +---+
  16.  |   |
  17.  O   |
  18. /|\ |
  19. /    |
  20.      |
  21. =========
  22. ''', '''
  23.  +---+
  24.  |   |
  25.  O   |
  26. /|\ |
  27.      |
  28.      |
  29. =========
  30. ''', '''
  31.  +---+
  32.  |   |
  33.  O   |
  34. /|   |
  35.      |
  36.      |
  37. =========''', '''
  38.  +---+
  39.  |   |
  40.  O   |
  41.  |   |
  42.      |
  43.      |
  44. =========
  45. ''', '''
  46.  +---+
  47.  |   |
  48.  O   |
  49.      |
  50.      |
  51.      |
  52. =========
  53. ''', '''
  54.  +---+
  55.  |   |
  56.      |
  57.      |
  58.      |
  59.      |
  60. =========
  61. ''']
  62.  
  63. chosen_word = random.choice(hangman_words.word_list)
  64.  
  65. display = []
  66. for letter in chosen_word:
  67.   display += ("_")
  68. print (hangman_art.logo + "\n")
  69. print(display)
  70.  
  71. str_display = " ".join(map(str, display))
  72.  
  73.  
  74. def again():
  75.   for each in range(len(chosen_word)):
  76.     if chosen_word[each] == guess:
  77.       display[each] = guess
  78.  
  79.  
  80. # def mistake():
  81. #   while guess not in chosen_word:
  82. #     lives = lives - 1
  83. #     if global lives == 0:
  84. #       print ("Game over!")
  85. #     else:
  86. #       print (f"You have {lives} lives left")
  87. lives = 7
  88.  
  89. used_letters = ""
  90.  
  91. while "_" in display and lives > 0:
  92.   guess = input("Guess a letter: \n").lower()
  93.   again()
  94.   clear()
  95.   if guess not in chosen_word:
  96.     lives = lives - 1
  97.     print (f"Letter {guess.upper()} is not a part of the word")
  98.     if lives > 0:
  99.       print (f"You have {lives} lives left")
  100.       print (stages[lives])
  101.   print (display)
  102.   used_letters += guess
  103.   print (f"Letter you already used : {used_letters.upper()}\n")
  104.  
  105.  
  106.  
  107. if lives == 0:
  108.   print ("You Loose!\n" + stages[lives] + "The word was " + chosen_word.upper())
  109. if "_" not in display:
  110.   print ("You Win!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement