int object does not support item assignment
<p>I'm in second year Comp. Sci at University and I've come across a problem in my most recent assignment. I have to make a Hangman game, 100% like their output and specifications. I would format the list with numbers but I don't know how, new to SO. My problem arises in the block:</p>

<pre><code>for i in range(0, stringSize, 1):
    answerStr[i] = '_'
</code></pre>

<p>where it gives me the error </p>

<pre><code>int object does not support item assignment
</code></pre>

<p>In other languages I could just make a string of size (userChosenWord) but I'm having trouble with Python's string library as well as its dynamic typing. In the assignment, I have to output the current string as <code>_____</code>, and if the user was to guess <code>e</code> for the word <code>horse</code>, I'd have to tell the user <code>Letters matched so far: ____e</code>. I hope that makes sense.</p>

<p>Also, if any of you have tips/comments on my code, please let me know. I'm always looking to learn.</p>

<pre><code>wordList = ['cow', 'horse', 'deer', 'elephant', 'lion', 'tiger', 'baboon', 'donkey', 'fox', 'giraffe'] #will work for words &lt;=100 chars
inputList = "abcdefghijklmnopqrstuvwxyz"
illegalInputList = "!@#$%^&amp;*()_+-=`~;:'\"&lt;,&gt;.?/|\\}]{["


def game():

    attemptsMade = 0
    print("Welcome to Hangman. Guess the mystery word with less than 6 mistakes.")

    userInputInteger = int(input("Please enter an integer number (0&lt;=number&lt;10) to choose the word in the list:"))
    if (0 &gt; userInputInteger or userInputInteger &gt; 9):
        print("Index is out of range.")
        game()

    for i in range(0, len(wordList)):
        if (userInputInteger == i):
            #userChosenWord is string from wordList[i]
            userChosenWord = wordList[i] 
            print("The length of the word is:", len(userChosenWord))
            break

    stringSize = len(userChosenWord)
    answerStr = len(userChosenWord)

    #make a temp string of _'s
    for i in range(0, stringSize, 1):
        answerStr[i] = '_'

    keyStr = userChosenWord

def play():

    guessChar = input("Please enter the letter you guess:")

    if guessChar not in inputList:
        print("You must enter a single, alphabetic character.")
        play()

    if guessChar in illegalInputList:
        print("Input must be an integer.")
        play()

    if (guessChar == ('' or ' ')):
        print("Empty input.")
        play()

    attemptsMade += 1

    if guessChar in userChosenWord:
        for i in range(0, stringSize, 1):
            if (keyStr[i] == guessChar):
                answerStr[i] = guessChar
        print("Letters matched so far: %s", answerStr)

    else:
        print("The letter is not in the word.")
        play()

    if (answerStr == userChosenWord):
        print("You have guessed the word. You win. \n Goodbye.")
        sys.exit()

    if (attemptsMade &lt;= 6):
        play()

    if (attemptsMade &gt; 6):
        print("Too many incorrect guesses. You lose. \n The word was: %s", userChosenWord)
        replayBool = bool(input("Replay? Y/N"))
        if (replayBool == 'y' or 'Y'):
            play()
        elif (replayBool == 'n' or 'N'):
            print("Goodbye.")

game()
</code></pre>
