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

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -