I am trying to continuously replace the substrings within a string based on user input but my string.replace syntax seems to replace the whole string with the substring from user input. here is the code:
import re
secret_word = 'COMPUTER'
clue = len(secret_word) * '-' # this step gives the user the nos of characters in secret_word
user_guess = input("Type a single letter here, then press enter: ")
user_guess = user_guess.upper()
if user_guess in secret_word:
index = [match.start() for match in re.finditer(user_guess, secret_word)] # this finds the index of the user guess in secret_word
print(index)
for i in index:
clue = clue.replace(clue[i], user_guess)
print("The word now looks like this: "+ clue)
I am not sure why it is not replacing only the substrings.