import random def choose_word(): words = ["python", "hangman", "challenge", "programming", "developer", "petersneal","piano","combine","liver","fireplace","muggy","loop","pyton","lossantos","night", "aeiou","python", "hangman", "challenge", "programming", "developer", "petersneal","piano","combine","liver","fireplace","muggy","loop","pyton","losSantos","night","skibidi","day","sun","people","sunshine","blood","walking","dead","saint","sinner","retribution"] 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 = 10 print("Welcome to Hangman!") print("Try to guess the word.") while attempts > 0: print("\nWord:", display_word(word, guessed_letters)) print(f"You have {attempts} attempts left.") guess = input("Guess a letter: ").lower() if len(guess) != 1 or not guess.isalpha(): print("Please enter a valid single letter.") continue if guess in guessed_letters: print("You've already guessed that letter.") continue guessed_letters.append(guess) if guess not in word: attempts -= 1 print(f"Wrong guess! The letter {guess} is not in the word.") if set(word) <= set(guessed_letters): print(f"Congratulations! You've guessed the word: {word}") break if attempts == 0: print(f"Sorry, you've lost! The word was: {word}") if __name__ == "__main__": hangman()