Why does this while loop not work
<p>Okay, so I've attached my entire code block for better context; I've also replaced the while loop with a for loop. However, it's still not functioning how I'm expecting. I want the ""s to be replaced by the correctly guessed letters when they are displayed, but instead, the correctly guessed letters are simply appearing at the beginning of the string of ""s. Also, certain letters I guess (maybe the last letter in the word? not sure) are throwing an error that says "string index out of range." Any ideas?</p>

<pre><code>compWord = choose_word(load_words())
playerWord = ""
for i in range(0, len(compWord)):
    playerWord = playerWord + "_"
playerBank = "abcdefghijklmnopqrstuvwxyz"
guesses = 8
def playerGuess (letter):
    global playerBank
    global guesses
    global compWord
    global playerWord
    i = 0
    counter = 0
    playerGuessBank = ""
    for ltr in compWord:
        i = i + 1
        if ltr == letter:
            playerWord = playerWord.replace(playerWord[i], letter, 1)
            counter += 1
            print(playerWord[i])
    playerGuessBank = playerGuessBank + letter
    playerBank = playerBank.replace(letter, "")
    guesses -= 1
    if counter == 0 and guesses &gt; 0:
        print("Oops! That letter is not in my word: " + playerWord)
        print("You have " + str(guesses) + " guesses left.")
        print("Available letters: " + playerBank)
        letterGuess = input("Please guess a letter: ")
        playerGuess(letterGuess)
    elif counter == 0 and guesses == 0:
        print("Oops! That letter is not in my word: " + playerWord)
        print("You have " + str(guesses) + " guesses left.")
        print("You lose fucker")
    else:
        if counter &gt; 0 and playerWord == compWord and guesses &gt; 0: 
            print("Good guess: " + playerWord)
            print("You have " + str(guesses) + " guesses left.")
            print("Available letters: " + playerBank)
            print("Congratulations, you won!")
        elif counter &gt; 0 and guesses &gt; 0:
            print("Good guess: " + playerWord)
            print("You have " + str(guesses) + " guesses left.")
            print("Available letters: " + playerBank)
            letterGuess = input("Please guess a letter: ")
            playerGuess(letterGuess)
        elif counter&gt; 0 and guesses == 0:
            print("Good guess: " + playerWord)
            print("You have " + str(guesses) + " guesses left.")
            print("You lose fucker")
            retry = input("would you like to try again, y/n?")
            input.lower
            if retry == "y":
                playerGuess(letterGuess)
print("Welcome to the game, Hangman!")
print("I am thinking of a word that is " + str(len(compWord)) + " letters long.")
print(playerWord)
print("You have " + str(guesses) + " guesses left.")
print("Available letters: " + playerBank)
letterGuess = input("Please guess a letter: ")
playerGuess(letterGuess)
</code></pre>
