Hangman (not printing guessed letters)-python
I have been trying to make a hangman game, Everything works fine except that it does not give the previous guessed letters in the correct places like the suppose the answer was "spoon" & you guessed the s first time you do it it will print in the proper place then you guess p the next one will look like
how do I bring it from that to:
import sys # Reads the number of letters lm = int(input("Enter number of letters: ")) lm2 = 0 # Defines the list letters = [None, None, None, None, None, None, None, None, None, None] #As many "None" values as you need, this one will only #support as many as 10 letters because there is only 10 None values while (lm == lm2) is False: if bool(letters[int(lm2)]) is False: letters[int(lm2)] = "_" lm2 = lm2 + 1 # This function prints the parts of the list that are not None values def word_print(): lm_check = 0 while (lm_check == lm) is False: sys.stdout.write(letters[int(lm_check)]) sys.stdout.flush() lm_check = lm_check + 1 # Call the function word_print()
In this case, just define
lm as the number of letters in the word and you can let the rest of the code do its thing.