I'm trying to print a string that includes letters in the alphabet. After each letter the user guesses, that guessed letter would be removed from the alphabet and then printed in the console to show which letters have not been guessed yet.
So far I have tried remove(), translate(), and filter(). Every time I've tried, the letter is successfully removed but when it's time to remove another letter, the first letter reappears in the string and the second letter is now removed. Basically, the letters do not stay removed and are only gone for that one loop.
Background info: I'm making a hangman app in python3. So part of the code I'm having trouble with is within a while loop that is in a function. I'm making a hangman app in python3. So part of the code I'm having trouble with is within a while loop that is in a function.
alphabet = "abcdefghijklmnopqrstuvwxyz"
guess = " "
print("These letters haven't been guessed yet: " + alphabet.translate({ord(guess): None}))
Expected result:
(Notice that the previous do not reappear after the second input.)
guess = input("Enter a letter: ")
Enter letter: a
These letters haven't been guessed yet: bcdefghi
guess = input("Enter a letter: ")
Enter letter: h
These letters haven't been guessed yet: bcdefgi
Actual result: (Notice that the letter 'a' has reappeared after user inputs 'h' .)
guess = input("Enter a letter: ")
Enter letter: a
These letters haven't been guessed yet: bcdefghi
guess = input("Enter a letter: ")
Enter letter: h
These letters haven't been guessed yet: abcdefgi
alphabet = alphabet.translate(...).alphabetitself. you need to reassign it.