import random from words import get_wordle_dictionary from game_utils import * SHOW_ANSWER: bool = True WORD_LENGTH: int = 5 WORDLE_DICTIONARY: list[str] = get_wordle_dictionary(WORD_LENGTH) def is_valid_guess(guess: str): guess = guess.strip().upper() if len(guess) != WORD_LENGTH: print("You can only guess words with FIVE letters!") return False if guess not in WORDLE_DICTIONARY: print("That's not a valid word with five letters!") return False return True def how_many_exact_matches(word1: str, word2: str) -> int: """ Returns the number of characters that appear identically at the same position in word1 and word2. """ ... def get_counts_of_letter(word: str, letter: str) -> int: """ Returns the number of occurrences of letter in word. """ ... def get_counts_of_letters(word: str) -> dict[str, int]: """ Returns a dictionary that maps all the distinct letters in word to the number of times they appear in word. For example, if word is "hello", this function would return {"h": 1, "e": 1, "l": 2, "o": 1}. """ ... def how_many_overall_matches(guess: str, answer: str) -> int: ... def how_many_misplaced_matches(guess, answer): overall = how_many_overall_matches(guess, answer) exact = how_many_exact_matches(guess, answer) return overall - exact def play_wordle_game(): answer = random.choice(WORDLE_DICTIONARY) if SHOW_ANSWER: print("(DEBUG) This answer is \"" + answer + "\"") guess = None while guess != answer: # print("Nice job! That's correct!") # print("You got " + str(exact) + " letter(s) exactly correct!") # print("You got " + str(misplaced) + " letter(s) misplaced!") again = True while again: play_wordle_game() again = prompt_yes_no('Would you like to play again (y/n)? ')