Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- word2 = open(r'C:\Users\Admin\.PyCharmCE2018.3\config\scratches\Hangman\words.txt').read().splitlines()
- word = random.choice(word2).lower()
- arr2 = []
- for i in range(len(word)):
- arr2.append(word[i])
- arr = ["_"]*len(word)
- error = []
- def check():
- count = 0
- print(*arr, "\n")
- while arr != arr2:
- letter = input("What is your next letter guess?:\n\n").lower()
- while len(letter) >= 2:
- letter = input("That was not a single letter, try again:\n\n").lower()
- if letter in arr or letter in error:
- letter = input("You already guessed that letter, try again:\n\n").lower()
- for i in range(len(word)):
- if letter in word[i]:
- count +=1
- arr[i] = letter
- if letter not in arr2:
- if letter not in error:
- error.append(letter)
- if len(error) > 10:
- return "You have failed"
- print("Incorrect Letters: [", *error, "] You have up to 10 incorrect guesses before you lose.\n")
- print(*arr, "\n")
- print("You guessed the word [" + word + "] correctly!")
- check()
Add Comment
Please, Sign In to add comment