import random
import sys
from termcolor import colored
def print_menu():
print("welcome to wordle !")
print("type a 5 letter word and hit enter\n")
def read_random_word():
with open('E:\kartikey\python\programs\wordle\words.txt') as word_database:
#splitline so every line in the text file gets stored as a diferent array
#block and since here every line is basically a word so every word gets stored as an individual array.
words=word_database.read().splitlines()
return random.choice(words).lower()
print_menu()
play_again=""
while play_again !="quit":
word=read_random_word()
for attempt in range(1,7):
guess=input().lower()
for i in range(min(len(guess),5)):
if guess[i]==word[i]:
#end="" is used so it doesnt go to a new line after printing the coloured letter
print(colored(guess[i],'green'), end="")
elif guess[i] in word:
print(colored(guess[i],'yellow'), end="")
else:
print(guess[i] , end="")
if guess==word:
print((f"\nyou got the word in {attempt} try"))
break
elif attempt==6:
print(f"sorry the wordle was {word}")
play_again=input("type quit to exit otherwise click enter")
the error im getting is:
welcome to wordle ! type a 5 letter word and hit enter poise ?[32mp?[0m?[32mo?[0m?[32mi?[0m?[32ms?[0m?[32me?[0m you got the word in 1 try
When I don't use the colored() function this error is not appearing but gives this issue when using it.
When i don't use the colored() function this error is not appearing but gives this issue when using it.
The issue is that what you see are escape sequences used to set the color of a single letter in the terminal output.
Apparently you use a console/terminal which doesn't support escape sequences or run your code in some other environment which output does not support coloring.
Your code runs perfectly and colors the hit letters in the output. Well done! Just run it in a console supporting escape sequences and enjoy!
Happy coding :)
Below a version of your code with following changes:
The wordle when run in a console/terminal supporting escape sequences for colors and text layout looks now as follows:
The meaning of colors in the wordle output is as follows:
And ... if you want to play it instead of playing around with its code just
wordsREVEAL_THE_WORD_TO_GUESS = TruetoFalseAUTOMATED_INPUT = TruetoFalse