Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import words
  2. random_word = words.get_words()
  3.  
  4. attempts = 10
  5. correct_guessed_letters = []
  6. guessed_letters = []
  7.  
  8. word_in_progress = random_word[0] + " __ " * (len(random_word) - 1)
  9.  
  10. player_name = input("Hello there! What's your name? ")
  11. print("Well then, " + player_name + ". It's time to play some hang man!")
  12. print("You have", attempts, "guesses to find the word. Good luck!")
  13.  
  14. while attempts > 0:
  15.  
  16. print(word_in_progress.upper())
  17. player_guess = (input("Guess a character: "))
  18.  
  19.  
  20. if not player_guess.isalpha(): # check the input is a letter. Also checks an input has been made.
  21. print("That is not a letter. Please try again.")
  22. continue
  23. elif len(player_guess) > 1: # check the input is only one letter
  24. print("That is more than one letter. Please try again.")
  25. continue
  26. elif player_guess in guessed_letters: # check if letter hasn't been guessed already
  27. print("You have already guessed that letter. Please try again.")
  28. continue
  29. else:
  30. pass
  31.  
  32. guessed_letters.append(player_guess)
  33.  
  34. if player_guess in random_word:
  35. correct_guessed_letters.append(player_guess)
  36.  
  37. for letter in range(len(random_word)):
  38. if player_guess == random_word[letter]:
  39. word_in_progress[letter] = player_guess
  40.  
  41. print("You are correct!")
  42. print("You have ", attempts, "guesses left.")
  43.  
  44. else:
  45. guessed_letters.append(player_guess)
  46. print("You are wrong!")
  47. attempts -=1
  48. print("You have ", attempts, "guesses left.")
  49.  
  50.  
  51. if attempts == 0:
  52. print("You have lost! Better luck next time :-)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement