A feature-rich console implementation of the classic Hangman game, built in pure Python with no external dependencies required (colors are optional via colorama).
========================================================
| 🎮 H A N G M A N 🎮
| Guess the word before time runs out!
========================================================
| Feature | Description |
|---|---|
| 💡 Categories | Words are tagged with emoji categories (Fruit, Animal, Sport, Tech, etc.) |
| 🎯 Difficulty levels | Easy / Medium / Hard — changes lives and word length |
| ❤️ Lives system | Visual life bar that shrinks with each wrong guess |
| 📈 Progress bar | Shows how much of the word you've uncovered |
| 💭 Hints | A one-time hint becomes available after 3 wrong guesses |
| 🏆 Session statistics | Tracks games played/won/lost, win rate, best score, and streaks |
| 🎲 Random messages | Varied flavor text for correct guesses, wrong guesses, wins, and losses |
| 🔄 Play again | Keep playing multiple rounds in one session |
| 🎨 Smart coloring | Auto-detects your environment and enables colors only where they'll render correctly |
- Python 3.8 or newer
- (Optional, for colored output)
colorama
Install colorama with:
pip install coloramaThe game runs perfectly fine without colorama — it just won't have colored text.
- Open Command Prompt or PowerShell.
- Navigate to the folder containing the script:
cd "path\to\your\folder"
- Run the game:
If that doesn't work, try:
python hangman.py
py hangman.py
You can also open and run the file directly in Python's IDLE editor (F5 or Run → Run Module). Colors will be automatically disabled since IDLE's Shell doesn't support ANSI color rendering — everything else works the same.
Note: This is a limitation of IDLE itself, not the game. For the full colored experience, use a real terminal as shown in Option 1.
- Choose a difficulty level:
Level Lives Word length 1 — Easy 🟢 8 3–5 letters 2 — Medium 🟡 6 6–7 letters 3 — Hard 🔴 4 8–12 letters - Guess one letter at a time.
- Correct letters reveal their position(s) in the word and add to your score.
- Wrong letters cost you a life and grow the gallows drawing.
- After 3 wrong guesses, you'll be offered an optional one-time hint.
- Win by revealing the whole word before you run out of lives.
- At the end of each round, your session statistics are shown, and you can choose to play again.
hangman.py → Main game script (single file, no external files needed)
README.md → This documentation
- Written entirely in the Python standard library, plus optional
coloramafor cross-platform color support. - Uses
dataclassesfor clean statistics tracking. - Auto-detects whether it's running inside IDLE (
idlelibinsys.modules) and disables ANSI colors there, since IDLE doesn't interpret them. - All functions are single-responsibility and documented with docstrings for readability and easy extension.
Ideas for extending the game:
- Add a timer per guess for extra challenge.
- Add multiplayer (take turns guessing).
- Load word lists from an external JSON/CSV file instead of hardcoding them.
- Add a "custom word" mode where a second player sets the word.
Free to use, modify, and share for learning and personal projects.