Day 007 of the 100 Days of Python challenge builds a Dragon Ball themed Hangman game. The program chooses a character name, hides its letters, and gives the player six lives to reveal the word.

This is the first project in the series to split code across multiple files instead of keeping everything in one script. It’s a small but important step toward writing larger programs: as a project grows, separating word lists and ASCII art from the actual game logic keeps each file focused and easier to read.

This guide walks through the complete Day 007 source code, including how it’s organized across files, and explains the logic behind rebuilding the guessed-word display every turn.

Project Overview

The project separates reusable assets into modules: hangman_words.py provides the word list, while hangman_art.py provides the logo, hangman drawings, and trophy art. The main file imports those values and controls the game itself.

day007/
├── main.py           # game logic
├── hangman_words.py   # word_list
└── hangman_art.py     # HANGMANART, LOGO, TROPHY

A random word is selected at the start of the game. The display is rebuilt on every turn by checking each letter of the word against the player’s correct guesses so far. Incorrect guesses are stored separately and reduce the lives counter.

Source Code

The Day 007 project’s game logic is contained in day007/main.py in the 100daysofpython repository, which imports its word list and art from the two supporting modules shown above:

import random
from hangman_words import word_list
from hangman_art import HANGMANART, LOGO, TROPHY

def hangman():
    print(LOGO)

    lives = 6
    chosen_word = random.choice(word_list)
    word_length = len(chosen_word)

    game_over = False
    correct_letters = []
    wrong_letters = []

    print("*******************************************")
    print("Welcome to the Dragon Ball Hangman Game!")
    print("*******************************************")
    print("Guess the name of a Dragon Ball character.\nYou have 6 chances before you lose.")
    print(f"Hint: The name you are looking for has {word_length} letters.")

    while not game_over:
        print(f"******************************** {lives}/6 LIVES LEFT ********************************")
        guess = input("\nGuess a letter: ").lower()

        if guess in correct_letters or guess in wrong_letters:
            print(f"You have already guessed '{guess}', try a different letter.")
            continue

        display = ""
        for letter in chosen_word:
            if letter == guess or letter in correct_letters:
                display += letter
            else:
                display += " _ "

        print("Word to guess: " + display)

        if guess in chosen_word:
            correct_letters.append(guess)
        else:
            wrong_letters.append(guess)
            lives -= 1
            print(f"You guessed '{guess}', that is not in the word. You lose a life.")

        if lives == 0:
            game_over = True
            print(HANGMANART[lives])
            print("******************************** GAME OVER ********************************")
            print(f"You lose! The word was: {chosen_word}")
        elif " _ " not in display:
            game_over = True
            print("******************************** YOU WIN! ********************************")
            print(f"You Win! The word was: {chosen_word}")
            print(TROPHY)
        else:
            print(HANGMANART[lives])
            print(f"Wrong guesses: {wrong_letters}")

if __name__ == "__main__":
    hangman()

How the Program Works

Splitting Code Into Modules

from hangman_words import word_list
from hangman_art import HANGMANART, LOGO, TROPHY

Instead of defining the word list and ASCII art directly in main.py, this project imports them from separate files. This keeps main.py focused entirely on game logic, while the content that has nothing to do with how the game works — just what it looks like and what words it uses — lives elsewhere. It’s the same principle behind organizing any larger codebase: separate what changes often (content) from what stays stable (logic).

Rebuilding the Display Every Turn

display = ""
for letter in chosen_word:
    if letter == guess or letter in correct_letters:
        display += letter
    else:
        display += " _ "

Rather than tracking which positions have been revealed, this loop rebuilds the entire display string from scratch on every guess. For each letter in the secret word, it checks two things: is this letter the one just guessed (letter == guess), or was it already guessed correctly in an earlier turn (letter in correct_letters)? Either way, the real letter is shown; otherwise, a blank placeholder is used.

Notice that guess is checked here before it’s added to correct_letters a few lines later — that’s intentional, and it’s what lets the display reflect the current guess immediately, without needing to update correct_letters first.

Tracking Lives and Checking Win/Loss

if lives == 0:
    game_over = True
    ...
elif " _ " not in display:
    game_over = True
    ...

The game ends one of two ways: lives reaches zero, or the display string no longer contains any " _ " placeholder, meaning every letter has been revealed. Using game_over as a Boolean flag, checked in the while not game_over: loop condition, is a clean way to let either ending exit the loop naturally.

What This Project Teaches

Day 007 practices:

  • Splitting a project across multiple files with import
  • Random selection from a list with random.choice()
  • Rebuilding a display string from scratch each iteration instead of tracking positions
  • Using a Boolean flag (game_over) to control a while loop’s exit condition
  • Detecting and rejecting repeated guesses with continue

Running the Project

git clone https://github.com/victorhugo81/100daysofpython.git
cd 100daysofpython/day007
python main.py

The supporting hangman_words.py and hangman_art.py files must stay in the same folder as main.py, since the game imports directly from them.

Possible Next Steps

Once you understand the existing code, try extending it:

  • Add a difficulty setting that changes the starting number of lives
  • Track and display the number of guesses used, not just remaining lives
  • Let the player pick a category (e.g., Saiyans only) before a word is chosen
  • Add a replay loop so the game restarts automatically after a win or loss

Conclusion

Day 007 of the 100 Days of Python challenge introduces multi-file Python projects, showing how splitting word lists and ASCII art into their own modules keeps the core game logic in main.py focused and readable. The rebuild-the-display-every-turn approach is also a useful pattern to recognize: sometimes recalculating something from scratch each time is simpler and less error-prone than trying to track incremental changes to it.

View the Day 007 source code on GitHub, then continue through the repository’s project index as you build more Python programs, one day and one small project at a time.