I have this function that is supposed to count points but it doesn\'t add them:
def Correct(totalPoints):
print \"Correct\"
totalPoints = totalPoints+1
You need your Correct
function to return something. Right now, you're printing a result and changing the totalPoints
local variable (which got copied in when passed as an argument to the function). When you make that change to totalPoints
inside of the Correct
function, it's only changing the local, copies variable, not the one that was passed in.
Try this instead:
def Correct(totalPoints):
print "Correct"
totalPoints = totalPoints+1
print "You have", totalPoints,"points"
return totalPoints
Now that it's returning the totalPoints, that variable can be brought back out to your regular program.