python - I have this function that is supposed to count points but it doesn't add them -


i have function supposed count points doesn't add them:

def correct(totalpoints):     print "correct"     totalpoints = totalpoints+1     print "you have", totalpoints,"points" 

here example of use in:

elif answer == 'nba':         nbaques = random.randint(0,len(nba1)-1)      nbavar = nba1[nbaques]      print nbavar     nbaanswer = raw_input()     nbaanswer = nbaanswer.lower()     if nbaanswer == nba2[nbaques]:         print correct(totalpoints)     elif nbaanswer != nba2[nbaques]:         print "false. correct answer was", nba2[nbaques]         nba1.remove(nbavar)         nba2.remove(nba2[nbaques])         print "choose another." 

i think mix local , global namespaces. if change correct(totalpoints) this:

def correct(totalpoints):     return totalpoints + 1 

and in "main code":

print correct(totalpoints) 

to

totalpoints = correct(totalpoints) print "you have", totalpoints, "points" 

it should work.

hope helps!


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? -