makes word choice random from every 5 letter english word

develop
Conor Walker 3 years ago
parent bbc47c4faf
commit 0f8377832d

2
.gitignore vendored

@ -0,0 +1,2 @@
virtual_environment
.idea

@ -1,3 +1,6 @@
import random
def getGuess(): def getGuess():
validGuess = False validGuess = False
guess = "" guess = ""
@ -10,6 +13,11 @@ def getGuess():
return guess return guess
def getWord():
lines = open('words').read().splitlines()
return random.choice(lines)
def checkRight(wordToGuess, guessSoFar): def checkRight(wordToGuess, guessSoFar):
if str(wordToGuess).upper() == str(guessSoFar).upper(): if str(wordToGuess).upper() == str(guessSoFar).upper():
return True return True
@ -20,12 +28,13 @@ def checkRight(wordToGuess, guessSoFar):
emptyWordGuess = ["_"]*5 emptyWordGuess = ["_"]*5
wrongLetters = set() wrongLetters = set()
rightLettersWrongPlace = set() rightLettersWrongPlace = set()
wordToGuess = ["P", "L", "A", "N", "S"] wordToGuess = list(getWord().upper())
print(wordToGuess)
userGuess = getGuess()
counter = 0 counter = 0
while counter < 5: while counter < 5:
userGuess = getGuess()
emptyWordGuess = ["_"]*5
for i in range(len(userGuess)): for i in range(len(userGuess)):
if wordToGuess[i] == userGuess[i]: if wordToGuess[i] == userGuess[i]:
emptyWordGuess[i] = userGuess[i] emptyWordGuess[i] = userGuess[i]
@ -43,7 +52,6 @@ while counter < 5:
print("Correct letters in the wrong place: " + str(rightLettersWrongPlace)) print("Correct letters in the wrong place: " + str(rightLettersWrongPlace))
print("Result: " + " ".join(emptyWordGuess)) print("Result: " + " ".join(emptyWordGuess))
counter += 1 counter += 1
userGuess = getGuess()
print("Ran out of guesses! The word was: ", "".join(wordToGuess)) print("Ran out of guesses! The word was: ", "".join(wordToGuess))
exit(69) exit(69)

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save