Guest User

Untitled

a guest
Dec 18th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import random
  2. word2 = open(r'C:\Users\Admin\.PyCharmCE2018.3\config\scratches\Hangman\words.txt').read().splitlines()
  3. word = random.choice(word2).lower()
  4. arr2 = []
  5. for i in range(len(word)):
  6. arr2.append(word[i])
  7. arr = ["_"]*len(word)
  8. error = []
  9. def check():
  10. count = 0
  11. print(*arr, "\n")
  12. while arr != arr2:
  13. letter = input("What is your next letter guess?:\n\n").lower()
  14. while len(letter) >= 2:
  15. letter = input("That was not a single letter, try again:\n\n").lower()
  16. if letter in arr or letter in error:
  17. letter = input("You already guessed that letter, try again:\n\n").lower()
  18. for i in range(len(word)):
  19. if letter in word[i]:
  20. count +=1
  21. arr[i] = letter
  22. if letter not in arr2:
  23. if letter not in error:
  24. error.append(letter)
  25. if len(error) > 10:
  26. return "You have failed"
  27. print("Incorrect Letters: [", *error, "] You have up to 10 incorrect guesses before you lose.\n")
  28. print(*arr, "\n")
  29. print("You guessed the word [" + word + "] correctly!")
  30. check()
Add Comment
Please, Sign In to add comment