Categories We Write About

Build a daily word game with Python

Creating a daily word game in Python can be both fun and educational. Here’s a complete example of a simple daily word guessing game inspired by popular formats like Wordle. The game picks a daily word (based on the date) and lets the player guess it, providing feedback on correct letters and positions.


python
import datetime import random # List of possible words (choose a manageable list or load from a file) WORD_LIST = [ "apple", "brain", "chair", "dream", "eagle", "flute", "grape", "house", "input", "joker", "knock", "lemon", "music", "night", "ocean", "plant", "queen", "river", "snake", "table", "uncle", "vivid", "water", "xenon", "yield", "zebra" ] def get_daily_word(word_list): """Select a word based on the current date to ensure daily consistency.""" today = datetime.date.today() # Use the date to create a seed so the word is consistent for a day seed = int(today.strftime('%Y%m%d')) random.seed(seed) return random.choice(word_list) def check_guess(secret_word, guess): """Check guess against secret word and return feedback.""" feedback = [] secret_word_letters = list(secret_word) # First pass: correct letter and position for i in range(len(guess)): if guess[i] == secret_word[i]: feedback.append('🟩') # Correct letter and position secret_word_letters[i] = None # Mark as used else: feedback.append(None) # Second pass: correct letter wrong position for i in range(len(guess)): if feedback[i] is None: if guess[i] in secret_word_letters: feedback[i] = '🟨' # Correct letter wrong position secret_word_letters[secret_word_letters.index(guess[i])] = None else: feedback[i] = '⬜' # Letter not in word return ''.join(feedback) def main(): word_length = 5 max_attempts = 6 secret_word = get_daily_word(WORD_LIST) print(f"Welcome to the Daily Word Game! Guess the {word_length}-letter word.") print(f"You have {max_attempts} attempts.n") attempts = 0 while attempts < max_attempts: guess = input(f"Attempt {attempts + 1}: ").lower().strip() if len(guess) != word_length: print(f"Please enter a {word_length}-letter word.") continue if guess not in WORD_LIST: print("Word not in dictionary. Try another word.") continue attempts += 1 feedback = check_guess(secret_word, guess) print(feedback) if guess == secret_word: print(f"Congratulations! You guessed the word in {attempts} attempts.") break else: print(f"Sorry! The word was '{secret_word}'.") if __name__ == "__main__": main()

How It Works:

  • The daily word is chosen deterministically based on the current date, so the word stays the same for all players on a given day.

  • The player has 6 attempts to guess the 5-letter word.

  • After each guess, feedback is shown using colored squares:

    • 🟩 (green) means the letter is correct and in the correct position.

    • 🟨 (yellow) means the letter is in the word but wrong position.

    • ⬜ (white) means the letter is not in the word.

  • Only words from the predefined list are accepted.

You can expand this by adding a larger word list, saving results, or building a graphical interface. Let me know if you want a version with those features!

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About