Skip to content

Instantly share code, notes, and snippets.

@jleclanche
Created February 22, 2022 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jleclanche/9e84bc8018137e12ea12be1708248d9a to your computer and use it in GitHub Desktop.
Save jleclanche/9e84bc8018137e12ea12be1708248d9a to your computer and use it in GitHub Desktop.
A simple CLI prototype of Wordle for someone to start playing with.
SOLUTION = "WORDS"
print("Guess a 5-letter word.")
def take_a_guess():
answer = input("> ")
answer = answer.upper()
if answer == SOLUTION:
return True
if len(answer) != 5:
print("Guess a 5-letter word")
return False
print("< ", end="")
for i, letter in enumerate(answer):
# print() with end="" doesn't print a full line
# This lets us print a character-by-character response
if letter == SOLUTION[i]:
# If the letter matches, print the letter
print(letter, end="")
elif letter in SOLUTION:
# If it's in the word, print "!"
print("!", end="")
else:
# If it's not in the word, print "-"
print("-", end="")
# Print a newline before the next guess
print()
guess_count = 0
while True:
guess_count += 1
correct = take_a_guess()
if correct:
print(f"Well done! Won in {guess_count} attempts.")
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment