r/learnprogramming • u/scy_404 • 1d ago
Debugging Anyone know how to fix the brackets in my program not being used correctly?
So I'm making a text based wordle clone thing in python and the way it shows the player details about the input letter (correct, wrong spot, incorrect) is with different kinds of brackets. The issue I'm having is that if a letter has appeared more times in the player's guess than is present in the word then it will only take the value of the first instance of that letter.
() = incorrect
{}= correct but wrong spot
[] = correct
This is the code that prints out the different letters:
while len(guess) != 5:
while len(guess) != 5:
guess = input(
"Please input a five letter word: ") # Input field for the user's guess
buffer = answer
for index in range(0, 5):
if guess[index] == answer[index]:
print(
"[" + guess[index] + "]"
) # adds square brackets to a letter indicate it is in the word and in the right spot
answer = answer.replace(guess[index], "*", 1)
elif guess[index] in answer:
print(
"{" + guess[index] + "}"
) # adds a squigly bracket to indicate the letter is in the word but in the wrong spot
answer = answer.replace(guess[index], "*", 1)
elif guess[index] != answer[index]:
print(
"(" + guess[index] + ")"
) # adds a curved bracket to indicate the letter is incorrect
answer = answer.replace(guess[index], "*", 1)
and this is an example of the bug (the correct word is wally):
Please input a username: test
Please input a five letter word: lalal
{l}
{a}
{l}
(a)
(l)