So my task is to create a wordle game which would ask the user a word and in the output shows word with marked letters, just letters and uppercase letters.It shows marked letters(y*) - if this letter is in the word to guess, uppercase letters if letter in the word and in the right place and just letter if this letter is not in the word.
The problem is that when the word to guess is "vigor" and i'm writing "rover", in the output, I get r* o* v* e R. But I should get r o* v* e R, because it's only one "r" in this word and it's on the right place.
I have tryed to change location of the else's in letter_finder function and to add more conditions, but only made it worse. I feel like the answer is very simple, but i'm thinking in wrong direction, so here is my code:
hidden_word = "vigor"
print(hidden_word)
user_word = input("Guess the word: ")
answer_list = []
def letter_finder():
mistakes = 0
for letter_in_hidden, letter_in_user in zip(hidden_word, user_word):
if hidden_word == user_word:
print("You win!")
break
# print(letter_in_hidden, letter_in_user)
elif letter_in_user in hidden_word and letter_in_user == letter_in_hidden:
answer_list.append(letter_in_user.upper())
" ".join(answer_list)
elif letter_in_user in hidden_word:
answer_list.append(letter_in_user + "*")
" ".join(answer_list)
elif letter_in_user not in hidden_word:
answer_list.append(letter_in_user)
" ".join(answer_list) + "."
# elif letter_in_user == letter_in_hidden:
elif user_word != hidden_word:
mistakes += 1
answer_list.clear()
elif mistakes == 6:
break
print(" ".join(answer_list))
answer_list.clear()
counter = 0
while hidden_word != user_word:
letter_finder()
user_word = str(input("Guess the word: "))
counter += 1
if counter == 5:
print(f"Sorry, you lose. The answer is: {hidden_word}")
break
I would probably start by casting both words to proper lists so we can index them. This also has the advantage that we don't modify
hidden_word
directly.Then I would process the words twice. Once to find and process exact matches and a second time to find and process partial matches.
Should return: