1
1
# Wordle in Python
2
2
3
3
Your task for the final assignment is to implement a [ Wordle] ( https://en.wikipedia.org/wiki/Wordle )
4
- clone in Python. The basis for you version of Wordle is the file
4
+ clone in Python. The basis for your version of Wordle is the file
5
5
` 5_letter_words.txt ` [[ 1]] ( https://www-cs-faculty.stanford.edu/~knuth/sgb.html ) .
6
6
It contains more than 5.700 five letter words. In order to build your
7
7
version of Wordle perform the following steps:
8
8
9
9
1 . Implement a function ` word_list() ` that reads the ` 5_letter_words.txt ` file and returns a list
10
10
of the words in the file.
11
11
1 . Implement a function ` random_word() ` that takes a list of words as a parameter and returns a random word
12
- from this list. This random word is the one, the player of Wordle has to guess.
12
+ from this list.
13
13
1 . Implement a function ` is_real_word() ` that takes two parameters, a guess and a word list and returns ` True ` if
14
14
the word is in the word list and ` False ` otherwise.
15
15
1 . Implement a function ` check_guess() ` that takes two parameters. The first is the guessed word and the second is the
@@ -18,19 +18,19 @@ version of Wordle perform the following steps:
18
18
- ` O ` for each character in the guess that is in the word but not at the correct position.
19
19
- ` _ ` for each character in the guess that is not part of the word.
20
20
For example, ` check_guess("birds", "words") ` should return ` __XXX ` .
21
- - If a letter is used twice in the guess word and exists only once in the word to be found,
21
+ - If a letter is used twice in the guessed word and exists only once in the word to be found,
22
22
then only one letter in the return string is marked. In case one of the two letters is
23
- positioned correctly, then this letters is marked with an ` X ` in the return string.
23
+ positioned correctly, then this letter is marked with an ` X ` in the return string.
24
24
For example, ` check_guess("carat", "train") ` should return ` _OO_O ` .
25
25
Another example, ` check_guess("taunt", "train") ` should return ` XO_O_ `
26
26
1 . Implement a function ` next_guess() ` that takes a word list as a parameter. The function asks the user
27
- for a guess converts the guess to lower case and checks if the guess is in the word list. If yes, the guess is returned.
28
- If not the function asks the user for another guess.
27
+ for a guess, converts the guess to lower case and checks if the guess is in the word list. If this is the case,
28
+ the guess is returned. Otherwise, the function asks the user for another guess.
29
29
1 . Implement a function ` play() ` that:
30
30
- Uses the functions ` word_list ` and ` random_word ` to select a random 5 letter word.
31
31
- Asks the user for a guess using the ` next_guess ` function.
32
32
- Checks each guess using the ` check_guess ` function and shows the result to the user.
33
- - Checks if the users guessed the right word with six guesses or less. If yes the
33
+ - Checks if the users guessed the right word with six guesses or less. If yes, the
34
34
user wins and the function prints ` You won! ` . Otherwise the user loses and the function
35
35
prints ` You lost! ` as well as ` The word was: ` followed by word the user had to find.
36
36
@@ -65,4 +65,4 @@ And here is another example execution of the program:
65
65
XXX_X
66
66
Please enter a guess: these
67
67
XXXXX
68
- You won!
68
+ You won!
0 commit comments