1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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!")
pass
again: bool = True
while again:
play_wordle_game()
again = prompt_yes_no('Would you like to play again (y/n)? ')