Last active
February 8, 2022 15:01
-
-
Save carloocchiena/b788402e60f86818756966d636caa6b0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Play it live on https://replit.com/@carlo_/wordletest#main.py | |
import random | |
from collections import Counter | |
from english_words import english_words_lower_alpha_set as words | |
words = list(words) | |
SECRET = words[random.choice(range(len(words)))] | |
COUNT = 1 | |
MAX_TRIAL = 10 | |
LONG = len(SECRET) | |
# print(SECRET) | |
print( | |
f""" | |
Welcome to Command Line version of Wordle.\n | |
You have to guess a {LONG} characters long word.\n | |
You have {MAX_TRIAL} trials.\n | |
Correct characters in correct place will be displayed as UPPERCASE.\n | |
Correct characters in wrong place will be displayed as lowercase.\n | |
Each trial is a stand-alone trial.\n | |
You have to manage wrong and right guesses!\n | |
Have Fun!\n | |
""" | |
) | |
while COUNT < MAX_TRIAL: | |
print(f"Trial {COUNT} out of {MAX_TRIAL}\n") | |
cloned_secret = list(SECRET) | |
char_items = Counter(SECRET) | |
guess = [] | |
initial_guess = input(f"Please input a {LONG} letter word:").lower() | |
while len(initial_guess) != LONG: | |
print(f"Your word was {len(initial_guess)} char long; it must be {LONG} char long. Try again.") | |
initial_guess = input(f"Please input a {LONG} letter word:") | |
else: | |
pass | |
if initial_guess == SECRET: | |
print(f"\nThe secret word is {SECRET}! You won!\n") | |
break | |
for i in range(len(cloned_secret)): | |
if initial_guess[i] == cloned_secret[i]: | |
if char_items[initial_guess[i]] > 0: | |
guess.append(initial_guess[i].upper()) | |
char_items[initial_guess[i]] -= 1 | |
else: | |
guess.append("_") | |
elif initial_guess[i] in cloned_secret: | |
if char_items[initial_guess[i]] > 0: | |
guess.append(initial_guess[i]) | |
char_items[initial_guess[i]] -= 1 | |
else: | |
guess.append("_") | |
else: | |
guess.append("_") | |
print("") | |
print(*guess) | |
print("") | |
COUNT += 1 | |
if COUNT == MAX_TRIAL: | |
print(f"Game over! The word was {SECRET}") | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment