I'm having a lot of trouble figuring this out
word = "hello"
hiddenWord = word
for i in range (0, len(hiddenWord)):
hiddenWord = hiddenWord.replace(hiddenWord[i], "_")
userInput = input("Enter letter: ")
for i in range(0, len(word)):
if word[i] == userInput:
hiddenWord = hiddenWord.replace(hiddenWord[i], userInput)
print(hiddenWord)
I'm trying to have it find where in the variable "word" the user inputted letter is and replace the underscore in the same location in "hiddenWord" with that letter, so it will gradually spell out the word as the user guesses letters.
What it's doing instead is iterating through "word" and when it reaches a letter equal to one in "word", it will replace every character in "hiddenWord" with that letter. So if I input l, it will iterate twice with no change, as it should, then change the string on the third and output "lllll" when the loop is finished. How would I get it to just change the relevant letters?