Reputation: 45
I am new to python and am building a wordle program in simple python. I will attach the code below: (Note- to understand this question you will have to be familiar with the game "Wordle" (https://www.nytimes.com/games/wordle/index.html))
i = 0
while 1>0:
guess_word = ["b", "l","a","n","k"]
word = input()
while i <= 4:
check = guess_word[i]
if check in word:
if word.find(check) == i:
print("green")
elif word.find(check) != i:
print("yellow")
elif check not in word:
print("grey")
i = i + 1
The problem with the code is that for some words it is giving the wrong answer (green, yellow, or grey) for some inputs, but the right answer in others. This is visible in the screenshot below:
As you can see, when the word "facts" is entered, it is saying that the letter "a" is grey, whereas in fact it should be yellow, and the letter "c" is "yellow", where it should in fact be "grey". The given output for "facts" is
grey
grey
yellow
grey
grey
where it should actually be
grey
yellow
grey
grey
grey
On the other hand, for the words "falts" and "blank" it is giving the right output. Please help me fix this problem.
Upvotes: 0
Views: 433
Reputation: 633
i = 0
while 1>0:
guess_word = "blank"
word = input()
while i <= 4:
check = word[i]
if check in guess_word:
if guess_word.find(check) == i:
print("green")
elif guess_word.find(check) != i:
print("yellow")
else:
print("grey")
i = i + 1
Upvotes: 0
Reputation: 330
You have confused guess_word
with word
. In this case, the solution to your wordle is "facts" and you are guessing the word "blank". If you print out check
you will see what the issue is:
b
grey
l
grey
a
yellow
n
grey
k
grey
Indeed, the third letter "a" is found in the word "facts"
Upvotes: 1