DEV Community

CodeWizardX1
CodeWizardX1

Posted on

Building a Classic Hangman Game in Python with Category Selection

As part of Codecademy's Computer Science Career Path, I was assigned to create a Python terminal-based game for my first portfolio project. I wanted to build something fun and engaging, so I decided to recreate the classic Hangman Game, but with a twist: category selection.

Instead of guessing a randomly selected word, the player can choose a category (such as Animals, Countries, or Movies) to help guide their guesses. This makes the game more strategic and enjoyable, while also allowing me to showcase my understanding of Python fundamentals. Below is a breakdown of my approach and a walk-through of the code.


Here’s a sneak peek of what the Hangman game looks like when running in the terminal:

The player is welcomed with an introductory screen, selects a category, and begins guessing letters to uncover the hidden word. The game even prints out fun ASCII art to show the progress of the poor stickman with each wrong guess!

hangman terminal game


I designed my Python Hangman game with simplicity and user engagement in mind. The game logic revolves around guessing a hidden word, and the player must try to figure it out one letter at a time. Here are some key parts of the code:

Category Selection: The game starts by letting the player choose from a list of categories. I used a Python dictionary to organize words into categories like "Animals," "Movies," and "Cities." This adds a fun twist because players can focus their guesses based on the category.

Random Word Selection: After a category is selected, the game randomly picks a word from that category. This is handled using Python’s random module, ensuring a different experience every time the game is played.

Handling Guesses: The player can guess one letter at a time. Correct guesses reveal the positions of the letter in the word, while incorrect guesses add to the hangman’s figure. The game ends either when the word is fully guessed or when the hangman is fully drawn (after 6 incorrect guesses).

ASCII Art: I used fun ASCII art to display the progress of the hangman, adding a visual element that players are familiar with from traditional Hangman games.


Check out the Code:
You can find the full source code for this project on my GitHub repository.


Developing this Hangman game as part of Codecademy’s portfolio project was a great way to practice core Python concepts like dictionaries, loops, and conditionals while also creating something that’s both fun and nostalgic. I may add further enhancements at a later date.

Top comments (0)