-
-
Save jleclanche/9e84bc8018137e12ea12be1708248d9a to your computer and use it in GitHub Desktop.
A simple CLI prototype of Wordle for someone to start playing with.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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