wordle.py

Created by tari-patrik-lfgeb

Created on June 09, 2025

1.61 KB


# 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()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.