DEV Community

mDex2409
mDex2409

Posted on

Building My First Python Terminal Game: Hangman

As part of Codecademy’s Computer Science 101 course, I recently built a simple Hangman game in Python. While it’s a beginner project, it was a great opportunity to practice structuring code, handling user input, and managing game logic.

The game follows the classic Hangman rules:

The program selects a random word from a predefined word bank.
The player guesses letters one at a time.
If they guess correctly, the letter is revealed in the word.
If they guess incorrectly, they lose a life.
The game ends when the player either guesses the word or runs out of lives.
Enter fullscreen mode Exit fullscreen mode

I structured the game using a HangmanGame class to manage game logic, along with a separate WordBank class to handle word selection based on difficulty.

One challenge was refactoring my initial script into a class-based structure. At first, I had everything in a single procedural script, which made it harder to manage. Breaking it into classes improved organization and made future updates easier.

I also learned a lot about handling user input, ensuring invalid inputs don’t break the game flow. This project was a great first step, and while I know I have a long way to go in my coding journey, I’m happy with the progress so far.

If you’re interested in checking out the code, you can find it here: https://github.com/mDex2409/CS101Hangman.

Top comments (1)

Collapse
 
breakpoint profile image
Rashid Javed

Seem like Repo does not exist.

Image description

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more