How do I make my python hangman game replace the underscores in the variable blanks with the correct letter if it is guessed.
I have the correct if statement but I am not sure how to get the letters replaced.
This is what I tried:
def main()
if choice in correctAnswer:
print("\nCorrect!\n------...\n")
index = 0
while index < len(correctAnswer):
index = correctAnswer.find(choice, index)
if index == -1:
break
print(index)
index += 1
used.append(choice)
places = []
place=correctAnswer.index(choice)
blanks[place]=choice
blanks=''.join(blanks)
main()
That gives me typeError: TypeError: 'str' object does not support item assignment
Any ideas on how to do this?
Thanks
UPDATE:
blanks = list(makeBoard(correctAnswer))
print (correctAnswer)
def main():
used = []
print(blanks)
choice = input("\nEnter a letter:")
if len(choice) == 1 and special_match(choice) == True:
if choice in correctAnswer:
print("\nCorrect!\n--------------------------------------------------------------------\n")
index = 0
while index < len(correctAnswer):
index = correctAnswer.find(choice, index)
if index == -1:
break
print(index)
index += 1
used.append(choice)
[choice if letter == choice else blank for blank, letter in zip(blanks, correctAnswer)]
main()