getting typeError while making a hangman game [closed]

3 weeks ago 13
ARTICLE AD BOX

In Python, the input() function returns a string. When you write

guess = input('Guess a letter: ').lower()

the variable is a string and not an integer. When attempting to access the index of a Python list, you need to use an integer. You cannot address a character as you try to do in this code and replace every instance of that.

if guess in word: guessword[guess] = word[guess] # word["a"] will raise a TypeError

Instead, write a loop that iterates through every character and compares it with guess.

if guess in word: # assuming guess is a single character string for i, letterInWord in enumerate(word): if letterInWord == guess: guessword[i] = guess
Read Entire Article