# wordle.py import random # β your word list β WORDS = [ "about","other","which","there","their", "apple","grape","drink","money","table", "plant","brain","light","trace","style" ] MAX_GUESSES = 6 YBOX = "π¨" # or use "β‘" if emoji doesnβt show up def pick_solution(): return WORDS[random.randrange(len(WORDS))] def get_feedback(guess, solution): # correct spot β letter, wrong spot β YBOX, absent β '_' fb = ['_'] * 5 sol = list(solution) # Greens: reveal letter for i in range(5): if guess[i] == solution[i]: fb[i] = guess[i].upper() sol[i] = None # Yellows: box for i in range(5): if fb[i] == '_' and guess[i] in sol: fb[i] = YBOX sol[sol.index(guess[i])] = None return "".join(fb) def play_game(): sol = pick_solution() print("\nNew Wordle! Guess the 5-letter word.") for turn in range(1, MAX_GUESSES+1): while True: g = input("[%d/%d] Guess: " % (turn, MAX_GUESSES)).strip().lower() if len(g)==5 and g.isalpha(): break print("Enter exactly 5 letters.") fb = get_feedback(g, sol) print("%s -> %s" % (g.upper(), fb)) if g == sol: print("Correct in %d guesses!" % turn) return print("Out of guesses. The word was %s." % sol.upper()) def main(): print("Welcome to NumWorks Wordle") while True: play_game() again = input("Play again? (Y/N): ").strip().lower() if not again.startswith('y'): print("Thanks for playing! π") break main()