Guest User

Untitled

a guest
Aug 23rd, 2019
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3.  
  4. def hangman():
  5. word_list = ["Python", "Java", "computer", "hacker", "painter"]
  6. random_number = random.randint(0, 4)
  7. word = word_list[random_number]
  8. wrong_guesses = 0
  9. stages = ["", "________ ", "| | ", "| 0 ", "| /|\ ", "| / \ ", "|"]
  10. remaining_letters = list(word)
  11. letter_board = ["__"] * len(word)
  12. win = False
  13. print('Welcome to Hangman')
  14. while wrong_guesses < len(stages) - 1:
  15. print('\n')
  16. guess = input("Guess a letter")
  17. if guess in remaining_letters:
  18. character_index = remaining_letters.index(guess)
  19. letter_board[character_index] = guess
  20. remaining_letters[character_index] = '$'
  21. else:
  22. wrong_guesses += 1
  23. print((' '.join(letter_board)))
  24. print('\n'.join(stages[0: wrong_guesses + 1]))
  25. if '__' not in letter_board:
  26. print('You win! The word was:')
  27. print(' '.join(letter_board))
  28. win = True
  29. break
  30. if not win:
  31. print('\n'.join(stages[0: wrong_guesses]))
  32. print('You lose! The words was {}'.format(word))
  33.  
  34. hangman()
RAW Paste Data