import random def choose_word(): word_list = ["apple", "banana", "cherry", "orange", "grape", "lemon"] return random.choice(word_list) def get_feedback(secret_word, guess): feedback = [] for i in range(len(secret_word)): if guess[i] == secret_word[i]: feedback.append('O') elif guess[i] in secret_word: feedback.append('X') else: feedback.append('-') return feedback def play_wordle(): secret_word = choose_word() max_attempts = 5 attempts = 0 guessed = False print("Welcome to Wordle!") print("Try to guess the secret word in 5 attempts.") while attempts < max_attempts: guess = input("Enter your guess: ").lower() if len(guess) != len(secret_word): print("Invalid guess. Please enter a word with", len(secret_word), "letters.") continue attempts += 1 feedback = get_feedback(secret_word, guess) print("Feedback:", ' '.join(feedback)) if feedback == ['O'] * len(secret_word): print("Congratulations! You guessed the word", secret_word, "correctly in", attempts, "attempts.") guessed = True break if not guessed: print("Sorry, you ran out of attempts. The secret word was", secret_word) play_wordle()