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
79
80
81
82
83
84
85
86
87
88
89
90
91
import random
from words import WORDLE_WORDS
from game_utils import *
SHOW_ANSWER = True
def is_valid_guess(guess: str):
guess = uppercase(guess.strip())
if len(guess) != 5:
print("You can only guess words with FIVE letters!")
return False
if guess not in WORDLE_WORDS:
print("That's not a valid word with five letters!")
return False
return True
def how_many_exact_matches(word1: str, word2: str) -> int:
count: int = 0
for i in range(len(word1)):
if word1[i] == word2[i]:
count += 1
return count
def get_counts_of_letters_1(word: str) -> dict[str, int]:
d: dict[str, int] = {}
for letter in UPPERCASE_LETTERS:
count: int = 0
for c in word:
if c == letter:
count += 1
d[letter] = count
return d
def get_counts_of_letters(word: str) -> dict[str, int]:
d: dict[str, int] = {}
for c in word:
if c in d:
d[c] = d[c] + 1
else:
d[c] = 0 + 1
return d
def how_many_overall_matches(guess: str, answer: str) -> int:
guess_count = get_counts_of_letters(guess)
answer_count = get_counts_of_letters(answer)
count: int = 0
for letter in UPPERCASE_LETTERS:
count_a: int = 0
if letter in guess_count:
count_a = guess_count[letter]
count_b: int = 0
if letter in answer_count:
count_b = answer_count[letter]
count += min(count_a, count_b)
return count
print(how_many_overall_matches("AAB", "BAC"))
def play_wordle_game():
answer = random.choice(WORDLE_WORDS)
if SHOW_ANSWER:
print("(DEBUG) This answer is \"" + answer + "\"")
guess = None
while guess != answer:
guess = input("Guess a word: ")
if guess == answer:
print("Nice job! That's correct!")
elif is_valid_guess(guess):
exact = how_many_exact_matches(guess, answer)
print("You got " + str(exact) + " letter(s) exactly correct!")
again = True
while again:
play_wordle_game()
again = prompt_yes_no('Would you like to play again (y/n)? ')