I have been working on this program for a few days and have most of it working, the only issue that I am having is when a word has multiple iterations pf the same letter. I need the program to print out all the letters that are the same when they are guessed. example if the word is apple and the user guesses p then I need both letter p's to be printed on the output line. Any help would be greatly appreciated, here is what I have.
import random #Program 4 Hangman #print the hangman partition def hangman(turn, correct): if correct > 0: turn = turn - correct if turn == 1: print('|') elif turn == 2: print('|') print('O') elif turn == 3: print(' |') print(' O') print('/') elif turn == 4: print(' |') print(' O') print('/|') elif turn == 5: print(' |') print(' O') print('/|\\') elif turn == 6: print(' |') print(' O') print('/|\\') print('/') elif turn == 7: print(' |') print(' O') print('/|\\') print('/ \\') #function to play the hangman game def game(word): word = word.upper() #capitalize the word print(word) hint = "-" * len(word) #setup the for the hidden word count = 0 # counter for the while loop for the 7 user inputs wrong =  number = 0 badGuess = 1 correctguess = 0 i = 1 while (count == 0): print (hint) guess = input('Please enter guess # ' + str(i) + ':') guess = guess.upper() #capitalize the user inputs #loop to see if the guess is in the hidden word if guess in word: print('That letter is in the word') index = word.find(str(guess)) x = list(hint) x[index] = guess hint = "".join(x) correctguess += 1 hangman(i, correctguess) # if guess is not in the hidden word go to the function to draw hangman else: hangman(i, correctguess) wrong.append(guess) w = " ".join(wrong) print ('The incorrect letters you have guessed: ' + w) badGuess += 1 if hint == word: print('Congratulations you have guessed the word.') break elif badGuess > 7: print('Sorry you took too many guesses that the word was ' + word) break i += 1 #open the file and read it into a list file= open('words.txt') word = file.readlines() #select a word at random for the game and pass that word to the function game select = random.choice(word) selection = select.rstrip() game(selection)