A classic terminal-based Hangman game written in Python. Guess the hidden word one letter at a time before the hangman is completed.
- Lightweight — no external libraries required
- Plays in your terminal with a simple text UI
- Randomized words from
words.txtfor every round - Replayable without restarting the program
- Python 3.7+
- No other dependencies
Install Python (brief platform guide):
-
macOS
-
Using Homebrew (recommended if you have Homebrew):
brew update brew install python
After install use python3 and pip3, e.g.
python3 --version. -
Or download the official installer from https://www.python.org/downloads/mac-osx/ and run it.
-
-
Windows
- Download the official installer from https://www.python.org/downloads/windows/ and run it. During installation, check "Add Python to PATH".
- Alternatively install from the Microsoft Store or use a package manager (Chocolatey:
choco install python). - Verify with
py -3 --versionorpython --versionin PowerShell/CMD.
-
Linux
-
Debian/Ubuntu:
sudo apt update sudo apt install python3 python3-venv
-
Fedora/CentOS:
sudo dnf install python3
-
Most distributions provide Python 3 via their package manager; you can also use pyenv to install specific versions.
-
Verification
Run:
python3 --version(or py -3 --version on some Windows setups) — it should report Python 3.7 or newer.
Optional (recommended for development)
Create and activate a virtual environment:
- macOS / Linux:
python3 -m venv venv
source venv/bin/activate- Windows (PowerShell):
python -m venv venv
venv\Scripts\Activate.ps1-
Open a terminal in the project directory (the directory that contains
main.py). -
Run the game with:
python3 main.py
Notes:
- The word list is read from
words.txt(a JSON array of words). Do not edit the file format. To add more words, you have to use the exact file format. - Enter a single lowercase letter as your guess. The game expects lowercase input (words are stored and compared in lowercase).
- To quit at any time, press Ctrl+C.
- The word list is read from
- When the program starts, type
startto begin. - During the game type a single letter and press Enter to guess.
- Correct guesses reveal that letter in the word.
- Incorrect guesses advance the hangman drawing. You are allowed 6 incorrect guesses; on the 7th stage the game ends.
- If you guess the entire word before running out of incorrect guesses, you win.
- After a round ends you may type
play againto start another round.
Type 'start' to start the game!
Then guess letters like:
_ _ _ _ _
Enter your guess: a
_ a _ _ _
The game will show the current hangman ASCII art, the partially revealed word, and prompt for the next guess.
main.py— game loop and input handlinghangman.py— ASCII art and helper for printing the hangmanutilities.py— input validation and result messageswords.txt— JSON list of words used by the gameLICENSE.md— project license
Contributions are welcome. If you'd like to propose a change or fix:
- Fork the repository
- Create a branch for your change
- Open a pull request with a short description of your changes
See LICENSE.md for license details.