import random

# List of words to choose from
word_list = ['culture', 'good', 'cherry', 'date', 'play', 'book', 'money']

# ASCII art for the hangman stages
hangman_stages = [
    '''
     _______
    |       |
    |       
    |       
    |      
    |      
    |___
    ''',
    '''
     _______
    |       |
    |       O
    |       
    |      
    |      
    |___
    ''',
    '''
     _______
    |       |
    |       O
    |       |
    |      
    |      
    |___
    ''',
    '''
     _______
    |       |
    |       O
    |      /|
    |      
    |      
    |___
    ''',
    '''
     _______
    |       |
    |       O
    |      /|\\
    |      
    |      
    |___
    ''',
    '''
     _______
    |       |
    |       O
    |      /|\\
    |      /
    |      
    |___
    ''',
    '''
     _______
    |       |
    |       O
    |      /|\\
    |      / \\
    |      
    |___
    '''
]


def choose_word():
    return random.choice(word_list)


def display_word(word, guessed_letters):
    displayed_word = ''
    for letter in word:
        if letter in guessed_letters:
            displayed_word += letter + ' '
        else:
            displayed_word += '_ '
    return displayed_word.strip()


def get_guess():
    while True:
        guess = input("Guess a letter: ")
        if len(guess) == 1 and guess.isalpha():
            return guess.lower()
        else:
            print("Invalid input. Please enter a single letter.")


def play_again():
    choice = input("Do you want to play again? (yes/no): ")
    return choice.lower() == 'yes'


def play_hangman():
    word = choose_word()
    guessed_letters = []
    incorrect_guesses = 0

    while True:
        print(hangman_stages[incorrect_guesses])
        print("Word:", display_word(word, guessed_letters))

        if incorrect_guesses == len(hangman_stages) - 1:
            print("Hangman! You lost.")
            print("The word was:", word)
            break

        guess = get_guess()

        if guess in guessed_letters:
            print("You already guessed that letter.")
            continue

        guessed_letters.append(guess)

        if guess in word:
            if set(word) == set(guessed_letters):
                print("Congratulations! You guessed the word:", word)
                break
            else:
                print("Correct guess!")
        else:
            print("Incorrect guess!")
            incorrect_guesses += 1


def main():
    print("Welcome to Hangman!")

    while True:
        play_hangman()

        if not play_again():
            break

    print("Thank you for playing Hangman!")


if __name__ == '__main__':
    main()