I'm currently coding a very simple hangman-game in order to get into Python and programming in general. Below you can find what I already have done. At this stage my code is able to pick a word from the list called "word_pool" at random, then display it with blanks instead of letters (so "kitty" turns into "_ _ _ _ _ " for example) and then check if the user's guess is in the word. That already works fine.
What I'm having trouble with is replacing the blanks if a guess is correct. Lets say the word is "kitty" and the user guesses "t", I want the encoded_word to get changed to "_ _ t t _". That's what I tried to do with the for-loop; I let i iterate over each character of the word and if it matches it should replace it in the encoded word. The reason it is i*2-1 in the encoded word is because between the underscores there are spaces. I then try to print the encoded word to see if it worked, but it just prints the underscore with spaces in between. Why is nothing replaced?
import random
word_pool = ["kitty", "dog", "teeth", "sitting"]
print("Guess the word!")
word = word_pool[random.randint(0, len(word_pool)-1)].upper()
print(word)
encoded_word = "_ "*len(word)
print(encoded_word)
guess = input("Which letter do you want to guess? ").upper()
if guess in word:
print(f"Yes, {guess} is correct!")
for i in range(0, len(word)):
if word[i] == guess:
encoded_word.replace(encoded_word[i*2-1], guess, 1)
print(encoded_word)
else:
print(f"No, {guess} isn't correct!")