Updating missing letters in hangman game
<p>I'm making a hangman game and have found a problem with my methodology for updating the answer. I have a variable that adds underscores equal to the amount of letters in the word the player needs to guess. However I can't figure out how to effectively update that when the player guesses a correct letter.</p>

<p>Here is my code</p>

<pre><code>import random
'''
HANGMAN IMAGE

print(" _________     ")
print("|         |    ")
print("|         0    ")
print("|        /|\\  ")
print("|        / \\  ")
print("|              ")
print("|              ")
'''

def game():
    print('''Welcome to hangman, you must guess letters to fill in the word.
Incorrect guesses will use up a turn, you have 7 turns before you lose.''')
    lines = open("wordBank.txt").read() 
    line = lines[0:] 

    words = line.split() 
    myword = random.choice(words).lower()
    letters = len(myword)
    print("Your word has " + str(letters) + " letters.")

    underscores = ""
    for x in range(0, letters):
        underscores += "_ "
    print(underscores)
    print(myword)
    l = set(myword)
    turn = 0
    guesses = []
    def guess():
        thisGuess = input("Type a letter and press Enter(Return) to guess: ")
        if thisGuess.lower() in l:

        else:
            print("Boo")

    guess()
game()
</code></pre>

<p>You probably need to reword your question as it's not clear what you are asking.  But you should look into string splicing.  If they guessed the letter "a" and it goes in the third slot then you could do something like</p>

<pre><code>underscores[:2] + 'a' + underscores[3:]
</code></pre>

<p>adapt for your code but that would replace the 3rd underscore with an "a".</p>

<p>UPDATE:
don't use a set, look up the index as you go.  Try something like this</p>

<pre><code>for index, letter in enumerate(my_word):
  if letter == guessed_letter:
    if not index == len(my_word) -1
      underscores = underscores[:index] + letter + underscores[index+1:]
    else:
      underscores = undescores[:-1] + letter
</code></pre>

python set