wordle game in python

To create a simple version of the game Wordle in Python, follow these steps:

  1. Define a secret word to be guessed by the player.
main.py
secret_word = "python"
23 chars
2 lines
  1. Ask the player to enter their guess as lowercase letters.
main.py
guess = input("Enter your guess: ").lower()
44 chars
2 lines
  1. Compare the guess with the secret word and count the number of matching letters.
main.py
matches = sum([guess[i] == secret_word[i] for i in range(len(guess))])
71 chars
2 lines
  1. Print out the number of matching letters, and whether the player has won or lost.
main.py
if matches == len(secret_word):
    print("Congratulations! You won.")
else:
    print(f"You have {matches} letters correct. Try again.")
138 chars
5 lines
  1. Repeat steps 2-4 until the player has guessed the correct word or has used up all of their guesses. You could do this with a while loop, which exits when the player wins or exceeds a certain number of incorrect guesses.

This is a basic implementation of Wordle in Python. You could make it more complex by adding more words, tracking statistics, or creating a graphical interface.

gistlibby LogSnag