import random

# List of words to choose from
word_list = ["a job", "Programming", "Technique", "Midocean", "university", "club", "Technology", "Vision"]

# Hangman ASCII art
hangman = [
    """
    +---+
        |
        |
        |
       ===""",
    """
    +---+
    O   |
        |
        |
       ===""",
    """
    +---+
    O   |
    |   |
        |
       ===""",
    """
    +---+
    O   |
   /|   |
        |
       ===""",
    """
    +---+
    O   |
   /|\\  |
        |
       ===""",
    """
    +---+
    O   |
   /|\\  |
   /    |
       ===""",
    """
    +---+
    O   |
   /|\\  |
   / \\  |
       ===""",
]

def get_random_word():
    """Choose a random word from the word list"""
    return random.choice(word_list)

def display_word(word, guessed_letters):
    """Display the word with placeholders for unguessed letters"""
    displayed_word = ""
    for letter in word:
        if letter in guessed_letters:
            displayed_word += letter + " "
        else:
            displayed_word += "_ "
    return displayed_word.strip()

def play_hangman():
    """Main function to play the Hangman game"""
    print("Welcome to Hangman!")
    word = get_random_word()
    guessed_letters = set()
    incorrect_guesses = 0

    while True:
        print(hangman[incorrect_guesses])
        print(display_word(word, guessed_letters))
        print("Guessed letters:", ", ".join(sorted(guessed_letters)))

        guess = input("Guess a letter: ").lower()

        if guess in guessed_letters:
            print("You already guessed that letter.")
            continue

        guessed_letters.add(guess)

        if guess in word:
            print("Correct guess!")
        else:
            print("Incorrect guess.")
            incorrect_guesses += 1

        if set(word).issubset(guessed_letters):
            print("Congratulations! You guessed the word:", word)
            break

        if incorrect_guesses == len(hangman) - 1:
            print(hangman[incorrect_guesses])
            print("Game over! You ran out of guesses.")
            print("The word was:", word)
            break

    play_again = input("Do you want to play again? (yes/no): ")
    if play_again.lower() == "yes":
        print()
        play_hangman()
    else:
        print("Thank you for playing Hangman!")

if __name__ == "__main__":
    play_hangman()