-
Notifications
You must be signed in to change notification settings - Fork 2
/
wordle.py
36 lines (30 loc) · 1.2 KB
/
wordle.py
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
"""Module for playing Wordle."""
import wordle_dictionary as wd
def start_game():
w = wd.get_word()
unusable = set()
for i in range(6):
guess = input(f"GUESS {i+1}:\nGuess a 5-letter word:\n\n").lower().strip()
while len(guess) != 5 or not wd.is_guessable(guess):
print("\nInvalid guess.")
guess = input(f"Guess a 5-letter word:\n\n").lower().strip()
hints = wd.validate_guess(guess, w)
for i, hint in enumerate(hints):
print(hint.value, end="")
if hint == wd.Hint.BLACK:
unusable.add(guess[i])
if i == 0:
print(f"\n\nNOTE:\n{wd.Hint.BLACK.value} = Not in word\n{wd.Hint.YELLOW.value} = In word, wrong position\n{wd.Hint.GREEN.value} = Correct\n")
else:
print("\n")
print(f"Cannot use: {unusable}\n")
if guess == w:
print(f"Congratulations! The word was: '{w}'\n")
break
else:
print(f"Game over! The word was: '{w}'\n")
again = input(f"Would you like to play again? (y/n): ").lower().strip()
if again == "y":
return start_game()
if __name__ == "__main__":
start_game()