DEV Community

Ioana Daria
Ioana Daria

Posted on

I Built a Wordle Clone in Python - Here's How You Can Too

Introduction

Wordle took the world by storm in 2022 — a simple daily word puzzle that had millions of people sharing colored squares on social media. What made it so compelling wasn't complexity - it was clarity. You get six guesses to find a hidden five-letter word, and each guess tells you exactly how close you are.

I wanted to understand that magic from the inside, so I built my own Wordle clone that runs entirely in the terminal using Python. This project was part of a personal challenge to build an interactive terminal program from scratch, version-control it with Git, and write about it. Whether you're a beginner looking for a fun project or a developer who wants to see how color-coded terminal output works, this post is for you.

What It Looks Like


Caption: The Wordle clone running in the terminal with color-coded feedback

How the Code Works

The full source is on GitHub: [https://github.com/ioanadaria/wordle-clone]

The program is built around three core ideas:

  1. ANSI color codes for terminal styling
    Standard Python print() can't produce colored output on its own, but terminals support ANSI escape codes — special character sequences that change text color and background. Green (\033[42m) marks a correct letter in the right position, yellow (\033[43m) marks a correct letter in the wrong position, and gray (\033[100m) means the letter isn't in the word at all.

  2. Two-pass feedback logic
    Scoring a guess against the secret word sounds simple but has a subtle edge case: duplicate letters. The get_feedback() function handles this with two passes — the first pass locks in all exact (green) matches, removing those letters from consideration. The second pass then checks remaining letters for yellow matches. This prevents a letter from being double-counted.

  3. Input validation with input()
    Every guess is validated in a loop: it must be exactly five characters and contain only letters. If not, the player is prompted again. This keeps the game from crashing on bad input and makes it feel polished.

The game loop itself is clean — six attempts, feedback after each guess, a win message if the player solves it, and a "play again?" prompt at the end.

Conclusion

Building this Wordle clone taught me more than I expected. The color output alone opened up a whole area of terminal programming I hadn't explored before, and the duplicate-letter problem forced me to think carefully about state. It's a small project, but it has real depth hiding inside it.

If you want to extend it, here are some ideas:

  • Load the word list from an external .txt file
  • Track and display win streaks
  • Add a hard mode that forces you to reuse confirmed letters
  • Port it to a web app using Flask

The full code is available here: [https://github.com/ioanadaria/wordle-clone] — feel free to fork it, break it, and make it your own.

Top comments (0)