Function not updating global variable
<p>I'm writing a program that simulates a game of Bunko for my compSci class, but I'm having issues getting the function <code>scoreCalc</code> to modify the global variable <code>playerScore</code>. The game pits a player against the computer, so I wanted to be able to use one function to determine the score and just pass an in argument to increment the correct score respectively. However, the function is not saving the value of <code>playerScore</code> across multiple plays, resetting to 0 with each round. I'm new to functions, so I'm sure the issue is likely something trivial, but I appreciate any and all help!</p>

<pre class="lang-python prettyprint-override"><code>dieList = []
sixCount = 0
playerScore = 0


def rollDice():    
    global sixCount
    sixCount = 0
    dieList.clear()

    die1 = random.randint(1,6)
    die2 = random.randint(1,6)
    die3 = random.randint(1,6)

    dieList.append(die1)
    dieList.append(die2)
    dieList.append(die3)

    print(dieList)

    for x in dieList:
        if x == 6:
            sixCount += 1
    print("sixCount:", sixCount)
    return


def scoreCalc(x):
    if sixCount == 1:
        x += 1
    elif sixCount == 2:
        x += 5
    elif sixCount == 3:
        x += 21
    return x


print()
print("Player's turn!")
print('*' * 30)
input("Press ENTER to roll the dice")
print()
rollDice()
print("Score:", scoreCalc(playerScore))
</code></pre>

<p>If you pass <code>playerScore</code> as a parameter and then do operations on it inside a function, <em>the global variable <code>playerScore</code> won't be changed</em>. </p>

<p>Why? <em>Numbers in Python are <a href="http://stackoverflow.com/a/8059504/4354477">immutable</a>.</em> </p>

<p>Wait, what?? Yes, when you do any operation on a number and populate some variable with the result (e.g. <code>i += 2</code>), <em>a new number object is created</em>. So, when you pass <code>playerScore</code> to a function, <em>a whole new object is getting passed</em>, so, what <code>scoreCalc</code> gets is not the actual <code>playerScore</code>, but its copy. Needless to say that changing the copy doesn't change the original.</p>

<p>The following will do the trick:</p>

<pre><code>def scoreCalc():
    global playerScore

    if sixCount == 1:
        playerScore += 1
    elif sixCount == 2:
        playerScore += 5
    elif sixCount == 3:
        playerScore += 21

    return playerScore
</code></pre>

python