I am making a hangman game in python. I use this code to check whether the input is in the word and update a list display
to show known letters:
if guess in word:
if guess not in display:
for a in word_sliced:
print(a)
if a == guess:
location = word_sliced.index(a)
display[location] = guess
else:
continue
else:
print("guess already used!")
else:
print("Oh no! Its not in the word!")
health -= 1
The problem is that only one letter will be matched. For example, if the word is book
and the user first guesses o
, display
will become ['_', 'o', '_', '_']
instead of the desired ['_', 'o', 'o', '_']
.
How can I fix the code so that all the repeated letters are updated?