Skip to content
The Chat Archive
gpt-4.1-mini-2025-04-14· OpenAI WildChat-4.8M (AI2)

Make a data dictionary for this code

  1. User

    Make a data dictionary for this code

  2. Assistant

    Sure! Please provide the code you want the data dictionary for.

  3. User

    These are the imports of the code.

    import random import time import os

    This gives the print a typewriter effect.

    This was function was made by chat GPT

    def typewriter_print(text, delay=0.03): for char in text: print(char, end='', flush=True) time.sleep(delay) print()

    This is the title screen of my game.

    I learned this from a Youtube video.

    def title_screen(): title = """


    |_ | | || __ ||_ | .' ___ | .' .| \ / || __ | \ \ /\ / / | |_ _| | | / .' _|/ .-. \ | / | | |_ _| \ / / / | | _ | | _ | | | | | | | |\ /| | | | _
    \ /\ / | |/ | _| |/ |\ .__.'\ - _ /
    | |
    /| | | |/ | / / |||| .__ .' \ .'|||||______|

    """
    os.system('cls' if os.name == 'nt' else 'clear')
    for line in title.split("\n"):
        typewriter_print(line, 0.005)# This is how fast the welcome will come into the screen witht he typewriter affect
    time.sleep(1)
    

    This is another welcoming message to the player.

    def show_title(): typewriter_print("🎮 Welcome to my word guessing game 🎈") typewriter_print("--------------------------------")

    This is my wordlist for the game for each difficulty

    def wordlist(): words_list = { "easy": ["jade", "love", "beta", "fall", "game"], "medium": ["python", "sprite", "launch", "broast", "backup"], "hard": ["software", "backward", "crambled", "compiler", "protocol"] }

    #I got this colouring idea from Muhammad Irham but I leant it from Youtube shorts.
    #Easy is in green, medium is yellow, and hard is red
    print("\033[32mEasy\033[0m")
    print("\033[33mMedium\033[0m")
    print("\033[91mHard\033[0m")
    
    difficulty = input("Choose difficulty(easy,medium,hard): ").lower()
    while difficulty not in words_list:
        typewriter_print("❌ Invalid choice.")
        difficulty = input("Choose difficulty(easy,medium,hard): ").lower()
    
    # Provide correct info after valid choice
    if difficulty == 'easy':
        typewriter_print("This will consist of 4 letter words")
    elif difficulty == 'medium':
        typewriter_print("This will consist of 6 letter words")
    else:
        typewriter_print("This will consist of 8 letter words")
    
    return difficulty, random.choice(words_list[difficulty])
    

    This shows the rules to the player.

    def show_rules(): typewriter_print("\n📜 Game Rules:") typewriter_print("1️⃣ Guess the secret word one letter at a time.") typewriter_print("2️⃣ You have 10 incorrect attempts.") typewriter_print("3️⃣ Good luck!\n")

    Bomb stages for Beat the Bomb mode

    I got the ASCII stages from https://www.asciiart.eu/weapons/explosives

    def bomb_stages(tries_left): stages = [ """ |*/|
    \ == / | | | | \ / / """, """ |*
    /|
    \ == / | |* | | \ / / """, """ |*/|
    \ == / | |
    | | \ /* / """, """ |*/|
    \ == / | |
    | |* \ /* / """, """ |*/|
    \ == / * | |
    | |* \ /* / """, """ |*/|
    \ == / * | |
    * | |* \ /* / """, """ |*/|
    \ == / * | |
    * | |* * \ /* / """, """ |*/|
    \ == / * | |
    * | |* * \ /* / 💥 """, """ |\💥/|
    \ == / * | |* * | |* * \ /* / 💥 """, """ |\💥/|
    \ == / * | |* * | | 🔥 * \ /* / 💥 """, """ .-^^---....,,--_
    -- ---
    (< 💥💥💥💥💥💥💥💥💥>) | BOOM!! | ._ 💥💥💥💥💥💥💥 _./
    --. . , ; .--'''
    | | |
    --- .-=|| | |=-. --- `-=#%&%#=-'
    --- | ; :| --- .,-#%&$@%#&#~,. 💥💥💥💥💥💥💥💥💥💥💥 """ ] index = 10 - tries_left if index >= len(stages): index = len(stages) - 1 print(stages[index])

    Update filename with difficulty suffix

    def get_highscore_filename(difficulty): return f"Data_{difficulty}.txt"

    #This will load the higscores in the Data.txt textfile. def load_highscores(difficulty, filename=None): if filename is None: filename = get_highscore_filename(difficulty) highscores = [] if os.path.exists(filename): with open(filename, "r") as f: for line in f: parts = line.strip().split(",") if len(parts) == 2: name, score = parts try: score = int(score) highscores.append((name, score)) except ValueError: pass return highscores

    This function saves the highscore of the player for each difficulty.

    def save_highscores(highscores, difficulty, filename=None): if filename is None: filename = get_highscore_filename(difficulty) with open(filename, "w") as f: for name, score in highscores: f.write(f"{name},{score}\n")

    This function adds the player highscore in the leaderboard.

    def add_highscore(name, score, difficulty, filename=None): highscores = load_highscores(difficulty, filename) highscores.append((name, score)) highscores.sort(key=lambda x: x[1], reverse=True) highscores = highscores[:3] save_highscores(highscores, difficulty, filename)

    This function shows the leaderboard after the player has put down the name

    def show_leaderboard(difficulty): print(f"\n🏆 Highscore Leaderboard ({difficulty.capitalize()}) 🏆") highscores = load_highscores(difficulty) if not highscores: print("No highscores yet, be the first!\n") return for i, (name, score) in enumerate(highscores, 1): print(f"{i}. {name} - {score} tries left") print()

    This is the function for the classic game mode.

    I learned some of this from Mohammad Nasir on this and used Youtube to boost my knowledge.

    def classic_game(secret_word, difficulty): tries = 10 guessed_letters = set() correct_letters = set(secret_word) while tries > 0: print("\nSecret word: ", end="") display_word = [letter if letter in guessed_letters else '_' for letter in secret_word] # Replaces the letters of the word with dashes. print(" ".join(display_word)) print(f"Tries left: {tries}") guess = input("Guess a letter: ").lower()

        if len(guess) != 1 or not guess.isalpha():
            typewriter_print("Please guess a single letter.", 0.02 )# If the player guesses more than 1 letter, then it will ask the player to input only 1 letter.
            continue
    
        if guess in guessed_letters:
            typewriter_print("You already guessed that letter." , 0.02) # If the player already guessed the letter before and inputs the same letter, it will tell the player to input a different letter.
            continue
            
    
        guessed_letters.add(guess)
    
        if guess in correct_letters:
            typewriter_print("✅Good guess!")
            if correct_letters.issubset(guessed_letters):
                typewriter_print(f"\n🎉 Congratulations! You guessed the word: {secret_word}")
                typewriter_print(f"You had {tries} tries left.")
                name = input("Enter your name for the leaderboard: ").strip()
                if name:
                    add_highscore(name, tries, difficulty)
                else:
                    print("No name entered. Score not added.")
                show_leaderboard(difficulty)
                break
        else:
            typewriter_print("❌Wrong guess. Try again...")
            tries -= 1
    else:
        typewriter_print(f"\n:( 💔You lost. The word was: {secret_word}\n")
    

    This is the function for Beat the Bomb game mode

    def beat_the_bomb(secret_word, difficulty): guessed_word = ["_"] * len(secret_word) guessed_letters = [] attempts = 10

    typewriter_print("\nBeat the Bomb mode: Guess before the bomb explodes!")
    bomb_stages(attempts)
    print("Word:", " ".join(guessed_word))
    
    while attempts > 0 and "_" in guessed_word:
        guess = input("Guess a letter: ").lower()
    
        if not guess.isalpha() or len(guess) != 1:
            typewriter_print("❗ Please enter a single letter.")
            continue
    
        if guess in guessed_letters:
            typewriter_print("❗ You already guessed that letter.")
            continue
    
        guessed_letters.append(guess)
    
        if guess in secret_word:
            for i in range(len(secret_word)):
                if secret_word[i] == guess:
                    guessed_word[i] = guess
            typewriter_print("✅ Good guess!")
        else:
            attempts -= 1
            typewriter_print(f"❌ Wrong guess! Attempts left: {attempts}")
            bomb_stages(attempts)
    
        print("Word:", " ".join(guessed_word))
    
    if "_" not in guessed_word:
        typewriter_print("🎉 You defused the bomb and guessed the word!")
        typewriter_print(f"You had {attempts} attempts left")
        name = input("Enter your name for leaderboard:").strip()
        if name:
            add_highscore(name, attempts, difficulty)
        else:
            print("No name entered, score not added")
        show_leaderboard(difficulty)
    else:
        bomb_stages(0)
        typewriter_print(f"💥 Boom! The bomb exploded. The word was: {secret_word}")
    

    def main(): title_screen()# This is the main menu at the end which allows the game to run. show_title()# This shows the title as the game begins. show_rules()# This is the rules function that I made before which will show the rules after the title.

    #This asks the player in a typewriter affect to select the gamemode.
    typewriter_print("Select Game Mode:")
    typewriter_print("1️⃣ Classic Mode🕹️")
    typewriter_print("2️⃣ Beat the Bomb🚀")
    
    
    #This only allows the player to input 1 or 2 for the game selection
    mode = input("Enter 1 or 2: ").strip()
    while mode not in ("1", "2"):
        typewriter_print("❌ Invalid choice. Please enter 1 or 2.")
        mode = input("Enter 1 or 2: ").strip()
    
    difficulty, secret_word = wordlist()  # Captures both difficulty and chosen word
    
    if mode == "1":
        classic_game(secret_word, difficulty)
    else:
        beat_the_bomb(secret_word, difficulty)
    
    play_again = input("\nWish to play again? (yes/no): ").lower()# If the player picks 1 then it will play the classic gamemode else it will play the beat the bomb mode.
    if play_again.startswith('y'):
        main()
    else:
        typewriter_print("Thanks for playing! Goodbye! 👋")
    

    if name == "main": main()

  4. Assistant

    Here's a detailed data dictionary for your word guessing game code. It describes the variables, data structures, and constants used throughout the program.


    Data Dictionary

    NameTypeScopeDescription
    textstrFunction parameterText string to be printed with typewriter effect in typewriter_print().
    delayfloatFunction parameterTime delay (seconds) between printing each character in typewriter_print(). Default is 0.03.
    titlestrLocal in title_screenMultiline string representing the ASCII art title of the game.
    linestrLocal in title_screenEach line of the title string used for typewriter printing.
    words_listdictLocal in wordlist()Dictionary mapping difficulty levels ("easy", "medium", "hard") to lists of words.
    difficultystrLocal in wordlist(), global in main()Stores selected difficulty level by player. One of "easy", "medium", or "hard".
    secret_wordstrLocal in wordlist(), argument in game modesThe word randomly chosen from the words_list for the current game.
    stageslist of strLocal in bomb_stagesList of ASCII art strings showing various bomb explosion stages indexed by tries left.
    indexintLocal in bomb_stagesIndex in stages list calculated to display current bomb stage based on attempts remaining.
    filenamestr or NoneParameter/Local in file-related functionsFilename for storing highscores, defaults to "Data_<difficulty>.txt" via get_highscore_filename().
    highscoreslist of tupleLocal in highscore functionsList of tuples (name, score) where name is a string and score is an integer representing tries left.
    linestrLocal in load_highscoresA line read from highscore file representing a player score entry "name,score".
    partslist of strLocal in load_highscoresResult of splitting line by comma. Should be [name, score].
    namestrPlayer input / function parametersPlayer's name input for leaderboard or used in scores.
    scoreintScore value for a playerNumber of tries remaining or attempts left when score was recorded.
    namestrLocal in game modesPlayer's name input after finishing a game to record score.
    triesintLocal in classic_gameNumber of remaining tries in classic mode; starts at 10.
    guessed_lettersset of strLocal in classic_gameSet containing all letters the player has guessed so far.
    correct_lettersset of strLocal in classic_gameSet of unique letters in the secret_word to match guesses against.
    display_wordlist of strLocal in classic_gameList representing guessed letters and underscores for unguessed letters in the secret word display.
    guessstrInput from player in game modesSingle letter string guessed by the player.
    guessed_wordlist of strLocal in beat_the_bombList representing the current known letters and underscores for the bomb mode word.
    guessed_letterslist of strLocal in beat_the_bombList of all letters guessed so far by the player.
    attemptsintLocal in beat_the_bombNumber of attempts remaining in beat the bomb mode; starts at 10.
    modestrLocal in main()Game mode selected by player, either "1" for classic or "2" for beat the bomb.
    play_againstrLocal in main()User input for playing the game again, typically "yes"/"no" or "y"/"n".

    Summary of Key Data Structures

    • words_list (dict):
      • Keys: "easy", "medium", "hard"
      • Values: list of words (strings) per difficulty level
    • highscores (list of tuples):
      • Each element is (player_name, score)
      • Sorted descending by score (tries left) and limited to top 3

    Functions and Parameters Overview Related to Data:

    FunctionParametersReturnsDescription
    typewriter_print(text, delay=0.03)text: str, delay: floatNonePrints text with a delay for typewriting effect
    title_screen()NoneNoneDisplays ASCII game title using typewriter effect
    show_title()NoneNonePrints welcome messages
    wordlist()None(difficulty: str, secret_word: str)Asks user difficulty and returns difficulty and a random word from list
    show_rules()NoneNoneDisplays the game rules
    bomb_stages(tries_left)tries_left: intNonePrints bomb ASCII art based on attempts left
    get_highscore_filename(difficulty)difficulty: strstrReturns highscore filename string based on difficulty
    load_highscores(difficulty, filename=None)difficulty: str, filename: Optional[str]list[(str, int)]Reads and returns highscores from file
    save_highscores(highscores, difficulty, filename=None)highscores: list[(str, int)], difficulty: str, filename: Optional[str]NoneSaves highscores list to file
    add_highscore(name, score, difficulty, filename=None)name: str, score: int, difficulty: str, filename: Optional[str]NoneAdds a new highscore entry and saves top 3 for difficulty
    show_leaderboard(difficulty)difficulty: strNonePrints the leaderboard for the difficulty
    classic_game(secret_word, difficulty)secret_word: str, difficulty: strNoneRuns classic game mode loop
    beat_the_bomb(secret_word, difficulty)secret_word: str, difficulty: strNoneRuns beat the bomb game mode loop
    main()NoneNoneOrchestrates game flow

    Let me know if you want me to organize this differently or include descriptions for constants like ANSI color codes or other details!