1 year ago
#372101
cosmias
unable to fix and find errors
name errors and unboundlocalerrors keep occurring and i have no idea what is wrong as all variables seem to be defined. also when i run the code, it does not output what i want it to and often outputs things twice or at the wrong time. attached an image below showing what happens when the code is run. two people working on this and neither can figure out whats happening
import sys
import random
def openMenu():
print ("""hi, welcome to katie and meliha's version of wordle!
rules for this game are:
1) there is a random 5 letter english word that the player has to
guess.
2) the player has 6 tries to guess the word correctly.
3) if the player guesses the exact position of a letter in the word
the box will turn green.
4) if the player guesses a letter that exists in the word of the day
but it's not in the correct position the box turns orange.
5) if the letter does not exist, it will stay gray
6) enjoy our amazing game """)
print ("""would you like to:
1. play game
2. quit game """)
openMenuchoice = int(input("enter your choice here: "))
if openMenuchoice == 2:
sys.exit
else:
Guess()
input ("""thank you for choosing to play our game! """)
def processGuess(answer, userGuess):
position = 0
clue = ""
for letter in userGuess:
if letter == answer[position]:
clue += "G"
elif letter in answer:
clue += "Y"
else:
clue += "-"
position += 1
print(clue)
return clue == "GGGGG"
word_list = []
word_file = open("wordList.txt.")
for word in word_file:
word_list.append(word.strip())
answer = random.choice(word_list)
num_of_guesses = 0
guessed_correctly = False
def Guess():
num_of_guesses = 0
while num_of_guesses < 6 and guessed_correctly == False:
userGuess = input("input a 5 letter word and press enter ")
print("you have guessed", userGuess)
num_of_guesses += 1
GuessLen = len(userGuess)
if GuessLen > 5:
print("your word is too long, try again ")
Guess()
elif GuessLen < 5:
print("your word is too short, it must be 5 letters ")
Guess()
else:
print("input a 5 letter word and press enter ")
guessed_correctly - processGuess(answer, userGuess)
if guessed_correctly == True:
print("you have guessed the correct word in", num_of_guesses, "times")
else:
print("you have used up your guesses, the correct word is", answer)
sys.exit
openMenu()
Guess()
processGuess()
python
wordle-game
0 Answers
Your Answer