import random def choose_word(): words = ['python', 'hangman', 'code', 'game', 'computer', 'programming', 'challenge', 'fun', 'learning', 'openai', 'artificial', 'intelligence', 'language', 'model', 'answer', 'question', 'knowledge', 'learning', 'challenge', 'creative', 'problem', 'solution', 'algorithm', 'data', 'structure', 'variable', 'function', 'loop', 'conditional', 'statement', 'iteration', 'list', 'dictionary', 'tuple', 'set', 'class', 'object'] return random.choice(words) def display_word(word, guessed_letters): display = '' for letter in word: if letter in guessed_letters: display += letter else: display += '_' return display def hangman(): word = choose_word() guessed_letters = [] attempts = 6 print("Welcome to Hangman!") print("Guess the word:", display_word(word, guessed_letters)) while attempts > 0: guess = input("Enter a letter: ").lower() if guess in guessed_letters: print("You already guessed that letter!") continue elif len(guess) != 1 or not guess.isalpha(): print("Please enter a single letter.") continue guessed_letters.append(guess) if guess not in word: attempts -= 1 print("Incorrect! Attempts left:", attempts) if attempts == 0: print("You ran out of attempts! The word was:", word) break else: print("Correct guess!") display = display_word(word, guessed_letters) print(display) if '_' not in display: print("Congratulations! You guessed the word:", word) break if __name__ == "__main__": hangman()
paste the code in the Instructions into python