Hello!
The goal of my first python project was to create a small game that could played within a terminal. I chose the game Wordle as it's currently quite popular and the game is very simplistic with daily replay value.
The few main sections of code focus on first: creating a random_word_selection function, second: create a eval_attempt function and third: write out a loop for what happens when the user guesses a certain way. The random_word_selection() function acts as a way to obtain a word from a text file randomly with random.choice(). Currently I've imported nltk to access a larger library of words than what I wrote in my text file. For the eval_attempt(), I used the (star),(+),(underscore) for encoding the list elements, then I created two lists one for the secret word (s2) and the attempt (a2) and proceeded to iterate over the types of guesses with pos and char as position and character. If the character in the attempt is in the right position and letter its marked a "star" and gets printed out green. If the guessed character is in the word but not the right position it's marked "+" and prints out yellow. If the character is not in the word at all its marked "underscore" and no colour is printed. In the last loop I wanted to return a string if you do not guess a five letter word or if you do get it right it will congratulate you! At the end if you don't guess in six tries it reveal the secret word to you and an option to replay or quit the game.
I created Wordle as a simple terminal game that aims to provide a little daily puzzle similar to sudoku, crossword, etc. This code shows my beginner knowledge of functions, modules, loops and lists.
Here is a link to the code:
https://github.com/dgilson74/WordleProject/blob/f6423bce66f870374dfcb4cc6340bfe9d5c38d1e/WordleProject.py
Top comments (0)