python - Writing a function to add points after points = 0 -
this question has answer here:
i writing function find out how many points earn. supposed add points points after when print points outside of function, says points = 0. here function...
points = 0 def correct(points): if question >= 0 , question <= 3: points = points + 100 print 'that 100 point question.' elif question >= 4 , question <= 7: points = points + 200 print 'that 200 point question.' elif question >= 8 , question <= 11: points = points + 300 print 'that 300 point question.' else: points = points + 400 print 'that 400 point question.' return points here example of function in code. if ranswer == random2[question]: #if right correct(points) print 'correct! have', points, 'points!' in end, should print amount of points have prints 0.
you need assign points return value correct(points).
points = correct(points)
integers immutable objects in python. when assign new value points inside correct(), it's not same original points had. points different integer object. reason need update points in calling code returned value correct(points).
Comments
Post a Comment