In this video you will learn how to write your own text-based version of the famous Wordle game in Python under 15 minutes. To make things simpler, we replace the graphics with just text.
If you want to take a look at the code you can get it from here:
Here we use a variety of coding constructs to create this game, including file I/O, console I/O, while-loop, function, for-loop, and if-statements. And believe it or not, many programs are created using these constructs as well!
0:30 brief description of the game
2:15 load words* from a file (file I/O, for-loop) and pick a random word
6:07 keep track of guesses and if a correct one is made (while-loop)
7:50 implement a step (console I/O, function)
9:25 define the main checking/cluing logic as a function (if-statements)
15:25 print the end-of-game message accordingly (if-statements)
17:57 test-run the program
20:18 a few challenges to make the game more robust: case-insensitivity, non-5-letter word warning
*the 10th word actually has 6 letters! We can fix that easily by replacing the word in the file.
The Wordle game has taken the internet by storm over the last few months. It has appeared in many people’s social media, TV shows, and even crossword puzzles. As of today over 2 million people have played this game.
The rules of the game are quite simple. A 5-letter word is chosen secretly. Then the player has 6 guesses. After each guess the player gets a clue: if the letter exists and is in the correct position, the letter is marked green; if the letter exists but is not in the correct position, the letter is marked yellow; and if the letter does not exist in the word, it is marked gray.
If you are curious about this game, or you want to give it a try to get a better, you can try it out for free from the creator here:
*update in early Feb 2022: NY Times has announced that it has acquired this game from the creator for a “low-seven figures”. Good for him. Not sure when it’ll become unavailable so try it out while you still can 🙂
In this video I decided to make the game text-based so it’s easier to create the interface. However, you can apply the same logic to create a graphical user interface using modules like turtle or pygame.
if you enjoyed this video, please Like, Subscribe, and share it with your friends!
9 Comments