Dilemma with replace in Python

Asked

Viewed 71 times

0

I am developing a hangman game in Python, and to accomplish the concealment of the word I use this little code:

if u1 in e: # Se u1 (Variável que armazena a letra do usuário)
    for c in str(e.strip()):  # Para cada letra na palavra fatiada
        if c.lower() not in lista:  # Se a letra não estiver na lista de letras que o usuário digitou até agora
            d = d.replace(str(c), ' _')  # Troque ela por ' _'
            # Assim o objetivo seria que só as letras que o user acertou ficassem a mostra

However, this code only works in the user’s first letter entry, because in the second entry it is already unusable due to all the letters of the variable that stores the word now have ' _' in place. Someone knows what I can do?

  • Preserve the original word.

  • Thank you very much, I realized that and it worked

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.